java - 如何使用 Rest-Assured 对来自公司代理后面的休息调用进行身份验证?

标签 java rest rest-assured

我尝试通过我们的公司代理调用休息服务,但不断收到响应:

407 Proxy Authentication Required. Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.

任何人都可以建议我可以尝试其他任何方法,或者支持 NTLM 的 RestAssured 替代方案吗?

这是我当前的代码:

    PreemptiveBasicAuthScheme auth = new PreemptiveBasicAuthScheme();
    auth.setUserName("my username");
    auth.setPassword("my password");

    // was getting desperate so tried adding this 
    System.setProperty("http.proxyHost", "XXXX");
    System.setProperty("http.proxyPort", "8080");
    System.setProperty("http.proxyUser", "my username");
    System.setProperty("http.proxyPassword", "my password");
    System.setProperty("https.proxyHost", "XXXX");
    System.setProperty("https.proxyPort", "8080");
    System.setProperty("https.proxyUser", "my username");
    System.setProperty("https.proxyPassword", "my password");

    Response r = RestAssured
            .given()
            // tried with and without this 
            .header("Proxy-Authorization", auth.generateAuthToken()) 
            .proxy("XXXX", 8080)
            .get(fullPath, key, key);

最佳答案

这里有几个问题 - 第一个我已经解决了,第二个我仍然被阻止。

设置代理身份验证只需设置正确的 header (如许多其他帖子中所述):

.header("Proxy-Authorization", auth.generateAuthToken())

阻碍我的是我正在调用一个在 https 而不是 http 上运行的服务,并且代理似乎没有被使用......所以回到绘图板。

关于java - 如何使用 Rest-Assured 对来自公司代理后面的休息调用进行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33006368/

相关文章:

java - 处理共享资源上的信号量冲突的最佳实践是什么?

java - 如何在 Android 上使用响应式扩展下载带有进度更新的文件

ajax - 使用RESTful URL进行jqGrid的内联编辑?

休息设计 : What Http verb should be used to retrieve a dynamic resource?

java - 放心 : How to make the POST rest assure call abstract for different type of Request objects

java - 放心请求不起作用

java - Android 系统覆盖窗口

java - 访问静态方法时的 Struts 2 Action 线程安全

api - 瑞典 Saas 电子商务解决方案,具有良好的 API 并与 Klarna 集成

java - JSON数据在Intellij的输出控制台中一行显示,放心