Can not add Http Header
I'm not sure if this project is still maintained, try asking.
I have configured a proxy with authentication in my android project. There are two options to achieve
- extends SimpleMiddleware, and add Proxy-Authorization in the onRequest function.
- Call addHeader [Proxy-Authorization] in AsyncHttpRequest. Check the http message through tcpdump, it tries to connect to the target proxy, but it does not carry the [Proxy-Authorization] I added.
I don't know if I used it wrong, attach a piece of code:
Headers header = new Headers();
String baseAuth = Base64.encodeToString(("test:12345678").getBytes(), Base64.NO_WRAP);
AsyncHttpRequest.setDefaultHeaders(header, Uri.parse(url));
header.set("Proxy-Authorization", "Basic " + baseAuth);
AsyncHttpGet request = new AsyncHttpGet(url);
request.setHeader("Proxy-Authorization", "Basic " + baseAuth);
view.setText(request.toString());
mClient.executeString(request, mCallback);
If I configure this parameter in the okhttp framework, I can successfully connect. So I think there is nothing wrong with the parameters of the header.
I checked the code of the AsyncHttp framework, I think the default does not support Proxy-Auth, so I want to manually add the http header, but it is invalid, if anyone has a suitable solution, please help me.
I tried to do some debugging, the header is correctly saved in the request, but when it is actually sent, there is only the host field, is this a bug?
To add, I found this code to force the use of the Host field, and did not use other fields in the Request
AsyncSSLSocketMiddleware.java ... String connect = String.format(Locale.ENGLISH, "CONNECT %s:%s HTTP/1.1\r\nHost: %s\r\n\r\n", uri.getHost(), port, uri.getHost()); data.request.logv("Proxying: " + connect); Util.writeAll(socket, connect.getBytes(), new CompletedCallback() { ...
In other words, the header I added will be used after the proxy is forwarded, not when the proxy is connected. I think it does not support the proxy with authentication, right?