![]() ![]() Using (var writer = new StreamReader(())) Var webException = (WebException)exception If (exception.GetType() = typeof(WebException)) The following code loops through all exceptions and writes out responses which helped me determine it was actually coming from the proxy: static void WriteUnderlyingResponse(Exception exception) This was happening for me because a Java proxy on the remote machine was timing out requests if the Java application did not respond in time, rendering the. Rqst.UserAgent = "Mozilla/4.0 (compatible MSIE 7.0 Windows NT 5.1)" agent, a default value is provided here. In order to solve the problem with the proxy not recognising the user Rqst.Proxy = GlobalProxySelection.GetEmptyWebProxy() No proxy details are required in the code. HttpWebRequest rqst = (HttpWebRequest)HttpWebRequest.Create(url) private static string SendRequest(string url, string postdata) The final working code is included below. Also, I changed the code to use GlobalProxySelection.GetEmptyWebProxy(), as described here. With the help of this I got a more detailed description of the problem: The proxy was returning the message: " The user agent is not recognized." So I set it manually. 509Certificate certificate,Īnd I keep getting the same 502 error. Public bool CheckValidationResult(ServicePoint srvPoint, Where public class AcceptAllCertificatePolicy : ICertificatePolicy So I added this line: ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy() The problem is, when calling GetRequestStream I keep getting a WebException with the message "The remote server returned an error: (502) Bad Gateway."Īt first I thought it had to do with the SSL certificate verification. StreamReader rsps = new StreamReader(rqst.GetResponse().GetResponseStream()) ((HttpWebRequest)rqst).KeepAlive = false PostStream.Write(byteData, 0, byteData.Length) Using (Stream postStream = rqst.GetRequestStream()) Proxy.Credentials = new NetworkCredential("username", "password", "mydomain") We have a proxy on the domain, so authentication is required. WebRequest rqst = HttpWebRequest.Create(url) Then I used this code as a reference to reimplement the request in c#: private static string SendRequest(string url, string postdata) If xmlHTTP.status = 200 And Len(message) > 0 And Not Err Then tRequestHeader "Content-Length", Len(postData) ![]() Set xmlHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0") I have the following snippet in classic ASP, to send a command and retrieve the response over SSL: Dim xmlHTTP ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |