Hi everyone i'm so hopeless so ask you guys. I'm trying to do a simple HTTP request but with my proxies I get 407 error code. I use Unirest and Java 8.
Unirest.config().proxy(host, port, usernameProxy, passwordProxy);
HttpResponse<JsonNode> response = Unirest.post(url).asJson();
String body = response.getBody().toString();
That's it, my url is private but i wrote it like this: "https://myurl.com/?param1=param¶m2.... It works proxyless but i'm stuck with proxies. Thanks a lot
Seems like the proxy server expects for the proxy credentials within the Headers , which Unirest
doesn't seem to propagate.
The header must specifically contain the "Proxy-Authorization"
key in order to the handshake be even started.
String proxyCred= "user:password";
String baseCred= Base64.getEncoder().encodeToString(proxyCred.getBytes());
HttpHeaders headers = new HttpHeaders();
headers.add("Proxy-Authorization", "Basic " + baseCred); // the proxy server needs this
This solution uses the Basic
mechanism; It may not work, as the proxy may expect another type of authentication. You'll know which one is by reading the Proxy-Authenticate
header within the server's response.
If the communication is not secured ( HTTP and not HTTP S ), you could read the response by sniffing the packet with some tool such as WireShark . Once you locate the 407 packet
, you could read inside the Proxy-Authenticate
value and modify your authorization method according do it.
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.