Exception downloading HTML code - c#

I'm trying to download the HTML code of one website using new WebClient().DownloadString() but I'm getting this exception all the time:
The underlying connection was closed. An unexpected error occured on a receive
Does anyone know how to solve this problem?

Check out this question. You might find the same solution works for you
Dotnet webclient timesout but browser works file for json webservice

Related

The remote server returned an error: (502) Bad Gateway. in MVC

I'm creating a shopify app using ASP.NET MVC, I made some code changes.
When I tried to run the application, I got the following error message
Error: The remote server returned an error: (502) Bad Gateway.
I always make backups for my application, because I got the error message, I decided to replace it with my backup file. But the same error still occurs.
I am a beginner both in the shopify app as well as C#. Can anyone explain why this happened and how to solve it?
You are trying to access an invalid connectionString shopUrl. Check this
İt is a proxy problem. Change current proxy to default proxy :
httpRequest.Proxy = GlobalProxySelection.GetEmptyWebProxy();

System.Net.WebException: The remote name could not be resolved

This kind of question has been asked several times, and I understand why it happens, and probably nothing we can do about it except retry.
I do have one question on name resolution though.
I am using AWS .Net SDK for 3.5 .Net. I am uploading a big file (>500MB up to 1.5GB, medical images). I call TransferUtility.Upload() method.
For most part the program works great.
Occasionally we get this error in the middle of the upload. Usually happens when the internet is slow.
I can catch the exception and retry, which means rery from the beginning since exception happens inside the AWS code.
My question is, if the program has resolved the s3 bucket name and has been uploading for a while why would it give me name resolution error instead of just using the cached resolved name?
Does each thread resolve the name independently and one of thread is failing since the network is saturated? Is this a computer setting? This error we were able to reproduce pretty consistently on a Windows 10 machine with Charter as ISP uploading a 800MB file.
The error occurred after about 250MB upload was done.
This is the actual exception
Exception during upload :Amazon.Runtime.AmazonServiceException:
A WebException with status NameResolutionFailure was thrown. --->
System.Net.WebException: The remote name could not be resolved: 'my-bucket.s3.amazonaws.com'
This web exception is telling you the there was an issue with the "Name Resolution". What it doesn't tell you is that the "name" it's referring to is the "EndpointRegion", for example: USEast1, USEast2 etc.
When using the Amazon.S3.Transfer.Transferutility it's crucial that the EndpointRegion you use in the Upload call MATCHES that of the bucket you're uploading into.
In my case using RegionEndpoint.GetBySystemName("USEast1") vs RegionEndpoint.GetBySystemName("US-East-1") was the difference maker.
Another cause for this issue could be DNS resolution. If your system is not able to perform DNS resolves it will give you this same error.

SignalR HubConnection Invalid URI

Based on an example I found, http://weblog.west-wind.com/posts/2013/Sep/04/SelfHosting-SignalR-in-a-Windows-Service, I'm implementing a SignalR host server within a Windows Service.
It all works fine but if I try:
SignalR = WebApp.Start<SignalRStartup>("http://*:8080/");
I get an unhandled exception of type `
'System.UriFormatException'` occurred in System.dll
Additional information: Invalid URI: The hostname could not be parsed.
It works fine if I use
SignalR = WebApp.Start<SignalRStartup>("http://localhost:8080/");
Probably a dumb assumption but based on the article I took this from, I assumed the *:8080 syntax would work. My question is, have I missed something or was the article incorrect and this format won't work?
So, the + does work... (and yes, I feel dumb) During my testing I think only 1/2 the time I remembered to run as administrator, which lead to bad test results since it was failing because of trying to open the port, and not because of the address.
I got clued into this by reading the Owin/Katana source code linked by #DigitalD. Turns out that not only does it support the + syntax, there is a comment from the code saying it's assuming it...
http://katanaproject.codeplex.com/SourceControl/latest#src/Microsoft.Owin.Host.HttpListener/OwinHttpListener.cs
// Assume http(s)://+:9090/BasePath/, including the first path slash. May be empty. Must end with a slash.
Have you tried removing the port number from the URI?
try
http://localhost instead of http://localhost:8080

How to set MaxBufferSize/MaxReceivedMessageSize in Windows Phone 7?

I've been having trouble querying a web server for information from my Windows Phone 7 app, and from my research, I've traced it back to MaxBufferSize/MaxReceivedMessageSize being too low. The problem is, I can't figure out how to change it. Every search result I find talks about the application being a WCF app, and to change the binding in ServiceReferences.ClientConfig. The solution from this post gives this example:
1. edit the ServiceReferences.ClientConfig to accept a large buffer.
<binding name="BasicHttpBinding_MosaicService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
However, I'm not using a WCF app, and I don't know what the equivalents of the above, and ServiceReferences.ClientConfig are for a regular WP7 application. Can anyone give me some help with this? I've done my best to figure it out myself but I'm getting nowhere.
For reference, in case someone else is having the problem I was (it took a really long time to figure out that this may be the problem), this is what is happening to me: I'm getting a WebException with the message: "The remote server returned an error: NotFound" thrown. And the relevant section of the stacktrace is:
at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
I'm not sure how you went from the error message "The remote server returned an error: NotFound" to thinking that your client can't handle the size of the response. Much more likely, the error message is correct and the URL you are requesting can't be found. Drop a breakpoint in your code where you kick off the request. What is the RequestUri property set to on your HttpWebRequest object? Copy that URL into a browser and you'll more than likely see that you get a "page not found". Fix your incorrect URL and all will be well.

webclient bugging out or what?

hi
I ran my project yesterday just fine, but today when I ran the same code it hangs on WebClient.DownloadFile() and eventually times out with this error message:
"An unhandled exception of type 'System.Net.WebException' occurred in System.dll"
So I tried running only the webclient in a new project, downloading from a hardcoded url that I know is up like this.
static void Main(string[] args)
{
WebClient client = new WebClient();
client.DownloadFile("http://www.ashersarlin.com/cartoons/officerap2.gif", "pic.gif");
}
Same thing happens. It creates an empty file "pic.gif" but times out eventually.
I could use some pointers. I'm new to .NET and have no idea how to troubleshoot this.
Your exact code works for me...
Perhaps your default proxy is messed up?
Suggestions:
Print out the detail of the WebException - it may give more hints
Use Wireshark to see what's going on at the network level. That should show you if it's trying to connect, what it's getting back etc.

Categories

Resources