This seems to be a very old issue however, all the said solutions are not working for me. I am making a request to a client and receive a HTTPS reponse that I used fiddler to capture early on, however now my application doesn't work without Fiddler certificates. When I select the descrypt HTTPS traffic in fiddler then the app works or else it doesn't even if I remove the HTTPS capture option from Fiddler and remove the fiddler certificate.
I have also tried to remove fiddler altogether but that din't solve the issue as well. I am out of options as of now. This is my code
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("Cert Location")
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf OnCertificateValidation)
ServicePointManager.Expect100Continue = False
Dim request As HttpWebRequest = CType(HttpWebRequest.Create(WebURL), HttpWebRequest)
request.Method = "POST"
Dim requestDataByte() As Byte = Encoding.UTF8.GetBytes(CreateRequestXML)
request.ContentLength = requestDataByte.Length
Dim requestdata As Stream = request.GetRequestStream()
requestdata.Write(requestDataByte, 0, requestDataByte.Length)
requestdata.Close()
request.GetRequestStream.Close()
request.ClientCertificates.Add(cert)
request.KeepAlive = False
Dim response As HttpWebResponse = CType(request.GetResponse, HttpWebResponse)
If response.StatusCode > 400 Then
MsgBox("Error:" + response.StatusDescription + vbCrLf + response.StatusCode)
End If
Dim response_stream As Stream = response.GetResponseStream
response_stream.Close()
response.Close()
Dim reader As StreamReader = New StreamReader(response_stream)
_response = reader.ReadToEnd
reader.Close()
I keep receiving the 500 internal server error.
Edit: I was not closing the response connection properly before however I modified that part of the code long back. Shouldn't that modification have solved my problem?
I have modified the code as per the posts I could find online. But still unable to resolve the issue.
It's unlikely that Fiddler's certificate has anything to do with this. The more likely explanation is that there's a problem in the way that your code is providing a client certificate to the server; that problem is remedied when Fiddler is in the middle (because Fiddler cannot take the client certificate sent by your application and pass it to the server).
So, stepping back, when you're running Fiddler, do you have a %AppData%\Documents\Fiddler\ClientCertificate.cer file on your disk? If so, Fiddler is sending that client certificate to the server. If not, then your server isn't getting a client certificate at all.
The solution to the above problem is to have the ClientCertificates.add() method just after you define the request object. And to close your response streams properly by calling the appropriate .Close() methods.
Related
I have some downtime at work and would like to spend it getting familiar with Haskell.
I am trying a simple HellowWorld.fs, which works fine at home, but doesn't at work.
I have a 'developer' account with the ability to install software, and generally IT can be convinced to unblock various network restrictions, but I have to be able to describe exactly what needs to be unblocked.
Here is what I am seeing:
C:\WorkSpace>stack HelloWorld.hs
Downloading lts-13.7 build plan ...
RedownloadHttpError (HttpExceptionRequest Request {
host = "raw.githubusercontent.com"
port = 443
secure = True
requestHeaders = [("User-Agent","The Haskell Stack")]
path = "/fpco/lts-haskell/master//lts-13.7.yaml"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
ConnectionTimeout)
Access violation in generated code when reading 00007ffc39deffff
This is from Windows 10 command prompt.
I can navigate just fine to raw.githubusercontent.com/fpco/lts-haskell/master//lts-13.7.yaml from my browser. Is that even where the problem is in this case? How can I diagnose what the problem is and then communicate the solution to IT? Even better, how can I solve it without getting IT involved?
I am attaching the below piece of code which works perfectly fine in localhost but throws web exception/socket when hosted in IIS on another server.
System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 40.113.232.243:443
It was throwing the same error in local too, unless I added this line-
httpWebRequest.Proxy = WebRequest.GetSystemWebProxy();
yet it throws socketexception when hosted in iis server.
public async Task<string> Get()
{
try
{
string uri = "https://hp-reporting-*****.azurewebsites.net/********";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.Timeout = 600000;
httpWebRequest.Proxy = WebRequest.GetSystemWebProxy(); // adding this line resolved error in local but still same issue persists when hosted in iis in another server
httpWebRequest.Method = "GET";
HttpWebResponse httpResponse = (HttpWebResponse)await httpWebRequest.GetResponseAsync();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
// this is your code here...
System.Xml.Linq.XNode node = JsonConvert.DeserializeXNode(response, "Root");
return node.ToString();
}
well, look at what that line does : https://learn.microsoft.com/en-us/dotnet/api/system.net.webrequest.getsystemwebproxy?view=netframework-4.7.2
On your local machine, you have a web proxy defined in Internet Explorer which you use when making the call. On the deployed IIS you clearly don't have it.
So, either you setup the server exactly how you setup your local machine or find another way to solve this issue locally, without using that local proxy. When you get it working, then you deploy again and it will work.
There is an application which works only in IE, not with any other browsers. I am using HtmlUnit to send the request by setting the mandatory field and clicking on the submit button, which is giving me Error Message -
An internal error has occurred during processing
Though i have specified browserversion while creating the webClient object, like this
WebClient webClient = null;
BrowserVersion bv = BrowserVersion.INTERNET_EXPLORER_11;
webClient = new WebClient(bv);
Can anybody please tell me what else am i missing here ?
Please let me know if there is any other way of getting this done here using HtmlUnit.
Our Dev/QA environments use self signed ssl certificates and we are trialing Abcpdf to convert html to pdf but the site where the html is rendered is run under a self signed SSL certificate.
Doc theDoc = new Doc();
theDoc.AddImageUrl("https://mysite/Test");
theDoc.Save(#"c:\tmp\htmlimport.pdf");
theDoc.Clear();
results in
WebSupergoo.ABCpdf9.Internal.PDFException : Unable to render HTML. Unable to access URL.
COM error 800c0019. Security certificate required to access this resource is invalid.
The manual states for TimeStampServiceUrl :
ABCpdf uses System.Net.WebRequest to send the time-stamping request.
You can use
System.Net.ServicePointManager.ServerCertificateValidationCallback to
customize trust relationship establishment when you connect to an
SSL/TLS channel.
But nothing similar for AddImageUrl(), I have tried anyway and the callback is never hit:
public class PdfTester
{
public void Test()
{
ServicePointManager.ServerCertificateValidationCallback = ServerCertificateValidation;
Doc theDoc = new Doc();
theDoc.AddImageUrl("https://mysite/Test");
theDoc.Save(#"c:\tmp\htmlimport.pdf");
theDoc.Clear();
}
private static bool ServerCertificateValidation(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
}
}
Any ideas how to bypass this validation in this scenario?
Try running this through fiddler, you may be encountering this issue caused by http://support.microsoft.com/kb/2677070
The symptoms of this issue lead you to focus on the target URL, but there may be several sub requests to the windows update URLs listed in that KB article as well as requests to the URL in the certificate. We had this issue, and fiddler was able to expose the 502 errors along the way which resulted in the 800C0019 error.
We fixed it by adding all the URLs exposed by fiddler to the customer's exceptions list, but there is fix from Microsoft here.
Of course this is just a possible resolution.
I've been looking for an answer to my problem for several days, but sadly had no luck. I hope you guys here can help me out.
So, what I want to do is just a simple call against the delicious.com API that returns me the recent bookmarks ("posts" in delicious terminology). Therefore you simply use the following URI and enter your credentials for logging in to delicious.com.
When I do this from a standard .NET4 Console Application with the magic of HttpWebRequest and setting the Credentials, it works as expected. Trying to do the same basic HttpWebRequest on the WP7 emulator leads to an WebException stating that "The remote server returned an error: NotFound.".
When diving deeper into this exception I can see that my Response has a StatusDescription of "Unauthorized". It seems like no authentication happend at all.
Next I tried - as I read that setting the Credentials sometiemes leads to problems - was to directly set the "Authorization" RequestHeader. Guess what, the result was the same.
I ended up with the following code and without ideas. I hope, somebody here is able to
help me out and point a way, how I can reach my bookmarks from my WP7.
public void RetrieveRecentBookmarks(string userName, string password)
{
HttpWebRequest request = HttpWebRequest.CreateHttp(requestString);
byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(userName + ":" + password)
string authInfo = Convert.ToBase64String(bytes);
request.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " + authInfo;
RequestState state = new RequestState(request);
IAsyncResult result = request.BeginGetResponse(GetResponseCallback, state);
}
private static void GetResponseCallback(IAsyncResult asynchronousResult)
{
RequestState state = asynchronousResult.AsyncState as RequestState;
HttpWebRequest request = state.Request as HttpWebRequest;
// Here is where it breaks...
HttpWebResponse response = request.EndGetResponse(asynchronousResult) as HttpWebResponse;
}
Thanks in advance!
As I now know, my code is absolutely correct and working. What was not working was the Emulator communication, as already mentioned by Shawn Kendrot.
I set up a completely fresh Win7, installed the WP7.1 SDK (and 7.1.1 Update) and it works like expected. So it seems like something blocked my calls from the emulator. I've got no idea, what it was, but I must admit, I don't care too much as it is working now.
Thank you Shawn for pointing out that there are sometimes problems with the Emulator and the web, that kicked me into the right direction.