简体   繁体   中英

How authenticate a rest call from behind a corporate proxy using Rest-Assured?

I'm trying to call a rest service via our corporate proxy but keep getting the response:

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

Can anyone suggest anything else I can try, or an alternative to RestAssured that supports NTLM?

This is my current code:

    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);

There were a couple of issues here - the first I've sorted, the second I'm still blocked on.

Setting the proxy authentication was a simple matter of setting the correct header (as has been noted in many other posts):

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

What was blocking me was that I'm calling a service running on https rather than http and the proxy does not appear to be used... so back to the drawing board.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM