I am working on this project, we have a desktop program that contacts an online server for store Because it is used in schools, getting the proxy setup is difficult, we have to allow users to specify proxy details to use them, otherwise it uses IE Attempts have also been attempted to bypass the addiction details, so the code tries to specify the specified proxy, if the default fails, if it fails, with credentials, if it fails, then zero.
The problem I am facing is where the proxy settings have to be changed in succession (for example, if their registration fails because the proxy is incorrect, they change a small thing and again Try, take seconds.) I end up with calls for HTTPRequest. Get Response (Timing Out), which allows the program to be frozen for a good time. Sometimes, if I leave one or two minutes between the changes, it is not stable, but not every time (just after 10mins it is tried again and it has time again).
I can not see anything such a code can be caused by that - although it looks a bit messy I do not think this server can reject the request, unless it is a normal server behavior, As I have tried to do it with our server and other requests like google.co.uk.
I am posting in hope that there is a code that can be able to spot something that is wrong with it, or very simple about what we are trying to do Know the way
The test that we run is without any proxy, so the first part is usually left. ApplyProxy is run for the first time, it works fine and the first attempt is to eliminate everything in the block. Second, it can be time-out on GetResponse for the first time and then go through the rest of the code, or it can work there and expire on the actual requests made for registration.
Code:
Apply zeroprocess () {
Boolean ProxySuccess = true; String WebRequestURI = @ "http://www.google.co.uk"; If (UseProxy) {try {String ProxyUrl = (ProxyUri.ToLower (.) Contains ("http: //"))? ProxyURI: "http: //" + ProxyUri; WebRequest.DefaultWebProxy = New WebProxy (ProxyUrl); If (! String.IsNullOrEmpty (ProxyUsername) & amp;! String.IsNullOrEmpty (ProxyPassword)) WebRequest.DefaultWebProxy.Credentials = New Network Credentials (ProxyUsername, ProxyPassword); HttpWebRequest request = HttpWebRequest.Create (WebRequestURI) as HttpWebRequest; request. Method = "received"; HttpWebResponse response = Request HTTP Web Response as GetResponse (); } Hold {ProxySuccess = false; }} If {(ProxySuccess ||! UseProxy) {try {WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy (); HttpWebRequest request = HttpWebRequest.Create (WebRequestURI) as HttpWebRequest; request. Method = "received"; HttpWebResponse response = Request HTTP Web Response as GetResponse (); } Catch (exception E) {// Try with credentials // WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy () from default; String newProxyURI = WebRequest.DefaultWebProxy.GetProxy (new URI (WebRequestURI)). ToString (); If (newProxyURI == String.Empty) {// We actually result in WebRequest.DefaultWebProxy = null; Return; } // continue WebProxy NewProxy = new WebProxy (newProxyURI); NewProxy.UseDefaultCredentials = True; New Proxy Credentials = Credential Cash Default credentials; WebRequest.DefaultWebProxy = NewProxy; Try {HttpWebRequest Request = HttpWebRequest.Create (WebRequestURI) as HttpWebRequest; request. Method = "received"; HttpWebResponse response = Request HTTP Web Response as GetResponse (); } Hold {WebRequest.DefaultWebProxy = null; }}}}}
Is not it the case to set up a timeout property HttpWebRequest? It may be that the connection is being made, but not servicing (for example, incorrect type of proxy server or stolen server), this may be the case that waiting for the timeout period before the end of the request - a The short time may end here.
No comments:
Post a Comment