Please, someone help me. I've been researching this for hours, have tried lots of different suggested fixes, and I'm at a total loss as to why I am still getting this error.
I have an ASP.NET 4.0 web page with the following code in it:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetHref);
// request.KeepAlive = false;
// request.ProtocolVersion = System.Net.HttpVersion.Version10;
// request.ServicePoint.Expect100Continue = false;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
I've tried every combination I can imagine of un-commenting the above 3 commented lines.
I have this in my web.config:
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing ="true"/>
</settings>
</system.net>
When I am running Fiddler on my dev machine, the page runs without exception and fiddler shows this message at the top of the return:
HTTP/1.0 200 This buggy server did not return headers
Without Fiddler running, I get the error every time on the request.GetResponse() line.
Well, I tried every suggestion I could find here on StackOverflow and elsewhere on the web, but never got an implementation of HttpWebRequest to work for me, so I tried using TcpClient instead after reading this:
How To Set useUnsafeHeaderParsing For .NET Compact Framework
To get it to work for me, I had to modify this line:
sw.WriteLine(string.Format("GET /{0} HTTP/1.1", pathAndQueryString));
to:
sw.WriteLine(string.Format("GET /{0} {1}", pathAndQueryString, Environment.NewLine+Environment.NewLine));
And that worked.
In asp.net with C# this issue is associated with port only.
Many programs use 80 port thats why you get this error, so get rid of this issue no configuration is required just close your
Skype, VPN softwares etc.. and it will resolve your issue.
In my case actually it was not Skype but hotspot shield (a free VPN) software was running in background quitting that software resolved my issue.
Related
I have been working on this problem for quite some time. I've read the many similar posts and their solutions don't help me (many posts are old and stale). I have a new Xamarin project and a localhost API that I am testing to. Initially I installed our production API locally and it doesn't connect. So I created a smaller test API and have had varying results in connecting. Xamarin Android will not connect with a "Failed to connect to localhost:XXXXX" message. I built a WPF project and get the same results. However I can connect to outside public API's (github) with both. I can connect to my localhost with a Windows forms desktop app and successfully get & post. Postman and httprepl both connect locally and successfully get & post. A couple of the other things the other posts suggested are 1) Client handler to ignore SSL - doesn't work, 2) Use the emulator's browser to connect to localhost - cannot connect. (this might be exposing where the problem really is but not sure).
Also The debugger seems to be behaving oddly. When the debugger gets to the HttpResponseMessageresponse.... line it rarely makes it to the next line so I cannot inspect the statuscode. The block I have below is in a try/catch and rarely makes it to the catch if the connection truly fails. Sometimes it will be caught at the catch and that's how I get the "failed to connect" message. Another developer here has run the project on his computer and gets the same results/errors on his computer.
HttpResponseMessage response = await client.SendAsync(request);
var Statuscode = response.StatusCode;
if (response.IsSuccessStatusCode)
{
var jsonbody = response.Content.ReadAsStringAsync().Result;
var ResponseBody = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
}
else
{
string oops = "Nothing";
}
I seem to be running out of options and am looking for any advice.
Thanks in advance.
Update: the code works on my desktop so it appears to be an issue with my server
I am trying to post some XML using vb/asp.net 4.0 via:
Dim request As HttpWebRequest = HttpWebRequest.Create(thePostingURL)
My code works for many clients, however there is one that I cannot seem to connect to.
I have attempted to research this and things I have tried based on posts I found are:
request.KeepAlive = False
request.KeepAlive = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Ssl3
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
Not all at the same time of course. I have tried running Wireshark while posting the XML and it appears to be failing on a "Handshake Failure (40)."
The client's url is https.
Not sure if this is a clue or not, but I cannot access the URL via IE8 while I can using Chrome. This is on a windows 2003 server.
Any ideas or suggestions of things to try?
I've noticed recently, that my code, that uses AFNetworking (latest version from master branch) stopped working properly under iOS 6.
Here's my code:
httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:baseURL]];
httpClient.operationQueue.maxConcurrentOperationCount = 1;
where httpClient is a class variable.
Next, I'm creating a request:
NSMutableURLRequest *signInRequest = [httpClient requestWithMethod:#"POST" path:#"/user/register" parameters:dataToSend];
signInRequest.timeoutInterval = 15.0;
signInRequest.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
AFJSONRequestOperation *signInOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:signInRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
// Blah
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
// Blah
}];
[httpClient enqueueHTTPRequestOperation:signInOperation];
All the other requests are constructed similarly. The first enqueued operation works well, I can get into success handler block. However, next calls to other requests are finished with fail handler and request timeout error, no matter how big is timeout value I choose.
I have done the same calls using plain NSURLConnection, writing a tons of code :), with success, requests were processed properly.
I switched to iOS 5 device, and the code above works fine.
I switched to 3G connection (iOS 6), and the code above works.
It seems like I have this problem only on WiFi connections (except the case when I'm in the same subnet with my REST server.)
Any thoughts on this?
Thank you in advance.
It seems you also posted an issue on AFNetworking's github and found the solution yourself :)!
It seems like iOS 6 changes something to TCP implementation or something. I moved server to third-party hosting and it is working now.
For future readers, the issue can be found here.
I am trying to set up an http post in my Blackberry app. I have successfully implemented this in my corresponding Android app, so I know the server it working find. I have tried several different things, and I'm not really getting errors, its just the info on the server is not getting updated. I have looked at this post:
Http POST in BlackBerry, and several others. I found them helpful, but they didn't ultimately solve my problem. Again, I don't get errors, but the server doesn't get updated. Here is the code I am currently using:
String url = "http://xxxx.com/ratings/add?;deviceside=true";
String postStr1 = "business_id=790";
String postStr2 = "&rating=4";
HttpConnection httpConnection = (HttpConnection) Connector.open(url);
httpConnection.setRequestMethod(HttpConnection.POST);
httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
encPostData.append("business_id", String.valueOf(790));
encPostData.append("rating", String.valueOf(4));
byte[] postData = encPostData.toString().getBytes("UTF-8");
httpConnection.setRequestProperty("Content-Length", String.valueOf(postData.length));
OutputStream os = httpConnection.openOutputStream();
os.write(postData);
os.flush();
Anyone have any ideas on what could be wrong?
A few things were going on. First, my simulator was not connecting to the internet properly. Once that got straightened out, I removed the
deviceside=true
from my url, and it now works great. Thanks all!
So I've got a bit of an issue I'm trying to work through. Perhaps some Flex guru could assist?
I have a WebService instance that attempts to load a WSDL file from our JBoss Application Server. If I do something like this:
webService = new WebService();
webService.destination = WebService.DEFAULT_DESTINATION_HTTP;
webService.wsdl = "http://<removed>/services/ApiService?wsdl";
webService.loadWSDL();
everything works fine. The WSDL is loaded successfully and the application can invoke methods against the web service.
The issue is when I need to add some HTTP authentication to the mix:
webService.setCredentials(userName, password);
this line ends up throwing an error stating that credentials are only supported on HTTPS. Ok fair enough, I want to use secure HTTPS anyway!
So then I tried to change it up to this...
webService = new WebService();
webService.destination = WebService.DEFAULT_DESTINATION_HTTPS;
webService.wsdl = "https://<removed>/services/ApiService?wsdl";
webService.setCredentials(userName, password);
webService.loadWSDL();
and now the WebService instance cannot load the WSDL. The error received is:
[FaultEvent fault=[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Unable to load WSDL. If currently online, please verify the URI and/or format of the WSDL (https://<removed>/services/ApiService?wsdl)"] messageId="6905CC5B-5317-C4B3-2D12-84647EE648A7" type="fault" bubbles=false cancelable=true eventPhase=2]
I can reach this URI in the browser just fine and it returns the WSDL as expected.
I am not a Flex guy (learning) but instead a Java developer. I am trying out Flex as a potential client to our system but this has caused me all kinds of grief today. Google doesn't appear to have any quick answers for me and I am a bit stumped.
First question on StackOverflow so hopefully this gets a bite somewhere and helps some other poor Java dev staying late in the office on a Friday night :-)
This seems to be related to your question. We are planning to use https in the future, so I'm curious to know the solution of your problem.