开发者

WebException in getResponse()

开发者 https://www.devze.com 2023-01-30 21:27 出处:网络
here my code- private string HttpContent(string url) { WebRequest objRequest = System.Net.HttpWebRequest.Create(url);

here my code-

private string HttpContent(string url)
{
    WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
    StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream());
    string result = sr.ReadToEnd();
    sr.Close();
    return result;
}

exception comes in 2nd line in objRequest.GetResponse(). If I open开发者_运维百科 it quick watch window I get:

'objRequest.GetResponse()' threw an exception of type 'System.Net.WebException'

"The remote server returned an error:(404) Not Found."


That seems pretty self-explanatory, really; Check your URL to make sure you're hitting the right location, or make sure that your target server is actually running.


It says what it says:

The remote server returned an error:(404) Not Found.

Your URL does not exist on the server and is not recognised. Your client code is not optimal but should work.


This error message is as it declares, the URL that you requested came back as a 404 error meaning that the page was not found.

Now it is possible that they are doing some odd "redirect" so you might try setting

objRequest.AllowAutoRedirect = true;

and see if that helps. However based on the 404 rather than a 301 or 302 response I'm not sure it will make any difference.


Try to call Url from your browser, if you get response you will be sure that your Url is working. Maybe in your computer there is proxy, you have pass proxy in your code.

That may help you


the problem is that the path [url] is incorrect you pass to method().

the URL may be not well form or check the url that 's work or not. if you not sure that's should always correct then you can use try catch if you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号