0

Are we supposed to write code differently to handle running through a system proxy for Http requests?

I have developed an application which uploads many files from a clients network over the internet via a REST API over a long period of time. I run it on a PC in their domain.

However, when I run it on one particular clients environment, after some arbitrary amount of time, all the requests start throwing an exception:

407 Proxy Authentication required.

The PC is configured to use a proxy. I don't specify any proxy information in my code, so my assumption is that it is just using the system proxy.

If I pause the uploads and wait a while before resuming, it seems to resolve the issue.

If I run multiple instances of my application on this machine at the same time, one may begin returning 407 exceptions while the other is humming away fine.

There is retry logic in the app, where when any given file will retry 3 times before giving up. I have never witnessed it recover from this 407 error when retrying (while it does recover on other types of errors).

Occasionally an individual file will get this error, as opposed to it happening for all uploads for a period of time.

Also, it may actually always behave this way when running through a proxy. This is just the first client I've had to run the app for that has had one configured.

I am at a complete loss as to whether this is a proxy configuration issue on the clients side, or an issue with my application.

I apologise if this isn't the correct StackExchange forum, I did post this on StackOverflow but it got no traction, so I am attempting to attack the problem from another angle.

1

The 407 error was probably issued by the proxy on the client side of the request. The response should include a Proxy-Authenticate header that indicates how the client application making the should authenticate with the proxy.

If the client application is a web browser and you are using JavaScript to access the REST API, then the web browser should be configured to use the proxy. If configured properly, then the web browser should handle 407 errors by performing authorization according to the proxy configuration.

If the client application is something you created, then your application must be configured to use a proxy. Since you tagged this as .net, you should look at System.Net.IWebProxy. For example, if you use something like WebRequest to send HTTP REST request, you can set the WebRequest.Proxy for each instance or do it once with static WebRequest.DefaultWebProxy.

I recommend you try to set it to the value of WebProxy.GetDefaultProxy() by default. I believe GetDefaultProxy() will return null if no proxy is configured, so the web request will behave as expected. You may also want to consider implementing override configuration to resolve a custom proxy configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.