WebRequest Proxy Authentification

Hey,

A customer is trying to run our app in it’s network which is behind a proxy. Normally that’s not an issue when using Unity 2022.1 or above (was a problem before as there was a bug that WebRequest didn’t detected Windows’ automatic proxy settings). But this time the customer uses a proxy which seems to require proxy authentification.

For testing we used two different methods namely WebRequest and HttpClient. The webRequest only returns

Failed to recieve data

whereas the HttpClient is more specific and returns

System.Net.Http.HttpRequestException: An error occured while sending the request ---> System.Net.WebException: (407) Proxy Authentification Required at System.Net.WebConnectionTunnel.Initialize.

Is it possible to pass any credentials (username and password) using Unity’s WebRequest?

Here is how to debug all networking:

Networking, UnityWebRequest, WWW, Postman, curl, WebAPI, etc:

And setting up a proxy can be very helpful too, in order to compare traffic:

I’m not sure how debugging would help me here. Since the error message is quite specific I was expecting that there is some method or something to pass the credentials required for the authentification. Does anybody know whether this is possible?

If nobody has a solution for this you someone at least think about a workaround for this? Is there something like a program which can take the requests of a certain application and redirect them to the proxy server while adding the required credentials?

I figured out so far that the proxy authorization requires a HTML header called “Proxy-Authorization” as described here: Proxy-Authorization - HTTP | MDN

UnityWebRequest allows to set custom headers so I tried to set the header with

request.SetRequestHeader("Proxy-Authorization", "Basic HereIsTheToken");.

Unfortunately it seems like Unity is blocking this header since I get the following exception:

InvalidOperationException: Cannot override system-specified headers.

I also tested it using HTTPClient and everything worked fine! But since Addressables is using UnityWebRequest that’s not the solution yet.

Any idea how I could overcome this restriction?