WebClient请求出现404错误 [英] 404 error with WebClient request

查看:100
本文介绍了WebClient请求出现404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我使用System.Net.WebClient类发出网页请求时

我找不到页面(404)我知道的网页存在错误。


这里有相关的代码:


aRequestedHTML = objWebClient.DownloadData(strUrl )

strRequestedHTML = objUTF8.GetString(aRequestedHTML)

aRequestedHTML是一个字节数组,strUrl是一个完整的URL,例如
http://10.0.1.6/categories/index.asp 和strRequestedHTML是<的输出br />
请求。


我得到的例外是:


WebException:远程服务器返回错误:( 404)未找到。

在System.Net.HttpWebRequest.CheckFinalStatus()

在System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)

at System.Net.HttpWebRequest.GetResponse()

at Neop.Module1.ReadWebPag e(String strUrl)


Web服务器位于运行应用程序的同一台机器上。我知道网址

存在,因为我可以在浏览器中看到它。此外,如果我从一台

不同的机器运行该应用程序,我不会收到任何错误,页面的HTML将返回



任何人都有任何想法?


Tony

Hi,
When I make a request for a web page using the System.Net.WebClient class
I''m getting a page not found (404) error for a webpage that I know exists.

Here''s the relevent bit of code:

aRequestedHTML = objWebClient.DownloadData(strUrl)
strRequestedHTML = objUTF8.GetString(aRequestedHTML)

aRequestedHTML is a byte array, strUrl is a full url such as
http://10.0.1.6/categories/index.asp and strRequestedHTML is the output of
the request.

The exception I get is:

WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at Neop.Module1.ReadWebPage(String strUrl)

The webserver is on the same machine the application runs on. I know the url
exists as I can see it in a browser. Also if I run the application from a
different machine I don''t get any errors and the HTML for the page is
returned.

Anyone got any ideas?

Tony

推荐答案

嗨Tony,

主要是一个绝对的问题,但我不知道哪一个,尝试新闻组

框架安全和adonet,也许你有更好的改变。


虽然我会尝试它,如果它是本地计算机127.0.0.1或

localhost也。

Cor
Hi Tony,

Mostly a sucurity isue but which one I would not know, try the newsgroup
framework security and adonet also, probably there you have a better change.

Although I would try it if it is a local computer with 127.0.0.1 or
localhost also.
Cor
我找不到一个页面找不到(404)我知道存在的网页错误。
这里有相关的代码:
aRequestedHTML = objWebClient.DownloadData (strUrl)
strRequestedHTML = objUTF8.GetString(aRequestedHTML)
http://10.0.1.6/categories/index.asp 和strRequestedHTML是输出>
请求。
我得到的例外是:

WebException:远程服务器返回错误:(404)Not Found。
在System.Net.HttpWebRequest .CheckFinalStatus()
在System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
在System.Net.HttpWebRequest.GetResponse()
在Neop.Module1.ReadWebPage(String strUrl)

Web服务器位于运行应用程序的同一台机器上。我知道
url存在,因为我可以在浏览器中看到它。此外,如果我从不同的机器运行应用程序,我不会收到任何错误,并且页面的HTML已经返回。
I''m getting a page not found (404) error for a webpage that I know exists.
Here''s the relevent bit of code:
aRequestedHTML = objWebClient.DownloadData(strUrl)
strRequestedHTML = objUTF8.GetString(aRequestedHTML)
aRequestedHTML is a byte array, strUrl is a full url such as
http://10.0.1.6/categories/index.asp and strRequestedHTML is the output > the request.
The exception I get is:

WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at Neop.Module1.ReadWebPage(String strUrl)

The webserver is on the same machine the application runs on. I know the url exists as I can see it in a browser. Also if I run the application from a
different machine I don''t get any errors and the HTML for the page is
returned.


我想我已经解决了我自己的问题,我在这里发布解决方案以防万一

之后在Google网上论坛搜索的人遇到了同样的问题。


似乎WebClient类没有按预期工作如果它的请求

转到

本地Web服务器请求IP地址。我已将IP地址

添加到具有主机名的本地主机文件中。我更改了我的应用程序,以便它使用主机名代替IP地址,一切正常。


Tony


I think I''ve solved my own problem, I''m posting the solution here in case
anyone searching at Google Groups later has encountered the same problem.

It seems that the WebClient class doesn''t work as expected if it''s requests
go to a
local web server with a request to an IP address. I''ve added the IP address
to my local hosts file with a host name. I changed my application so that it
used the host name in place of the IP address and everything worked.

Tony



Tony,

只是一个猜测,但这可能是一个DNS问题。如果用127.0.0.0替换

的IP地址怎么办?当

以编程方式调用它时,这会有什么不同。


或者,尝试在主机文件中输入您的计算机的条目,并按名称而不是通过IP地址调用URL来查看是否有帮助。

$ b $问候 - OHM

Tony B写道:
Tony,
Just a guess but could this be a DNS issue. What if you replace
the IP address with the 127.0.0.0, does this make any difference when
calling it programitically.

Alternatively, try putting an entry for your machine in the hosts file and
calling the URL by name rather than by IP address to see if this helps.

Regards - OHM
Tony B wrote:

当我使用System.Net.WebClient请求网页时
我正在为一个我知道存在的网页找不到页面错误(404)错误。

这里有相关的代码:

aRequestedHTML = objWebClient.DownloadData(strUrl)
strRequestedHTML = objUTF8.GetString(aRequestedHTML)
aRequestedHTML是一个字节数组,strUrl是一个完整的URL,例如
http://10.0.1.6/categories/index.asp 和strRequestedHTML是
我得到的例外是:

WebException:远程服务器在System.Net.HttpWebRequest上返回错误:(404)Not Found。
。在System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)的CheckFinalStatus()
在Neop.Module1.ReadWebPage(String strUrl)< />
Web服务器位于运行应用程序的同一台机器上。我知道网址存在,因为我可以在浏览器中看到它。此外,如果我从另一台机器运行
应用程序,我不会收到任何错误,并返回该页面的HTML。

任何人都有任何想法?
Hi,
When I make a request for a web page using the System.Net.WebClient
class I''m getting a page not found (404) error for a webpage that I
know exists.

Here''s the relevent bit of code:

aRequestedHTML = objWebClient.DownloadData(strUrl)
strRequestedHTML = objUTF8.GetString(aRequestedHTML)

aRequestedHTML is a byte array, strUrl is a full url such as
http://10.0.1.6/categories/index.asp and strRequestedHTML is the
output of the request.

The exception I get is:

WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at Neop.Module1.ReadWebPage(String strUrl)

The webserver is on the same machine the application runs on. I know
the url exists as I can see it in a browser. Also if I run the
application from a different machine I don''t get any errors and the
HTML for the page is returned.

Anyone got any ideas?

Tony



这篇关于WebClient请求出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆