一些网址的空HttpWebResponse长度(带有查询?) [英] Empty HttpWebResponse length for some url (with queries?)

查看:68
本文介绍了一些网址的空HttpWebResponse长度(带有查询?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于某些网址

(例如 http://v3.espacenet.com/origdoc?DB=E...=WO2005028634)

的内容长度为HttpWebResponse我得到了请求.GetResponse在

为空。 response.GetResponseStream()也是空的。但是,我能够在浏览器中打开URL(URL地址保持不变;它不是

重定向)


下面是代码片段:


HttpWebRequest req =(HttpWebRequest)WebRequest.Create(pageAddress);

HttpWebResponse resp =(HttpWebResponse)req。 GetResponse();

StreamReader sr = new StreamReader(resp.GetResponseStream());

string pageData = sr.ReadToEnd();


回复的内容类型是text / html;字符集= ISO-8859-1"并且

HttpStatusCode没问题。 pageData长度为0.


是否应修改URL以使其工作(例如某些替换)?


我缺少什么?


谢谢


杰森

For some URLs
(e.g.http://v3.espacenet.com/origdoc?DB=E...=WO2005028634),
the content length for the HttpWebResponse I get with request.GetResponse in
empty. The response.GetResponseStream() also empty. However, I am able to
open the URL in the browser (the URL address remains the same; it is not
redirected)

Here is the code snippet:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string pageData = sr.ReadToEnd();

The Content Type for the response is "text/html; charset=iso-8859-1" and the
HttpStatusCode was OK. The pageData length is 0.

Should the URL be modified for it to work (e.g. some substitution)?

What am I missing?

Thanks

Jason

推荐答案




您使用的是:


StreamReader sr = new StreamReader(resp.GetResponseStream());


难道你不能使用它:


StreamReader sr = new StreamReader(resp.GetResponse()。GetResponseStream());


其余的对我来说很好!

希望它有所帮助...



Hi,

You are using this:

StreamReader sr = new StreamReader(resp.GetResponseStream());

Shouldn''t you be using this:

StreamReader sr = new StreamReader(resp.GetResponse().GetResponseStream( ));

The rest seens fine to me!
Hope it helps...
o.f




长度为空还是对象为空?来自webrequests的流由

默认不允许搜索所以它不知道手头的长度..如果你

在获得流之后在代码中放一个中断你应该能够将b / b $ b悬停在流上,看看它是否为空,它不应该为null

除非它出错,但是它可能不知道长度...


Jason Manfield写道:

Is the length empty or is the object empty? Streams from webrequests by
default dont allow seeking so it won''t know the length off hand.. if you
put a break in the code after it gets the stream you should be able to
hover over the stream and see if it''s null or not, it shouldn''t be null
unless it got an error, but it may not know the length...

Jason Manfield wrote:
对于某些网址
(例如 http://v3.espacenet.com/origdoc?DB = E ... = WO2005028634)
空的请求获取的HttpWebResponse的内容长度.GetResponse为空。 response.GetResponseStream()也是空的。但是,我能够在浏览器中打开URL(URL地址保持不变;它没有被重定向)

这是代码片段:

HttpWebRequest req =(HttpWebRequest)WebRequest.Create(pageAddress);
HttpWebResponse resp =(HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream()) ;
string pageData = sr.ReadToEnd();

响应的内容类型是text / html;字符集= ISO-8859-1"并且
HttpStatusCode没问题。 pageData长度为0.

是否应修改URL以使其工作(例如某些替换)?

我缺少什么?

谢谢

Jason
For some URLs
(e.g.http://v3.espacenet.com/origdoc?DB=E...=WO2005028634),
the content length for the HttpWebResponse I get with request.GetResponse in
empty. The response.GetResponseStream() also empty. However, I am able to
open the URL in the browser (the URL address remains the same; it is not
redirected)

Here is the code snippet:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string pageData = sr.ReadToEnd();

The Content Type for the response is "text/html; charset=iso-8859-1" and the
HttpStatusCode was OK. The pageData length is 0.

Should the URL be modified for it to work (e.g. some substitution)?

What am I missing?

Thanks

Jason



对象不为空。 pageData的长度(使用

StreamReader.readToEnd()创建)为0.而resp.ContentLength也为0.但是它确实显示了ContentType之类的信息(其中是text / html; charset = iso-8859-1)。

HttpStatusCode也没关系。仅此URL发生此问题。

WebRequest中是否有特殊要求,其中带有查询字符串的URL在

中?


Michael McCarthy写道:
The object is not empty. The length of pageData (created with
StreamReader.readToEnd()) is 0. And the resp.ContentLength is also 0. But it
does show info like ContentType (which is "text/html; charset=iso-8859-1").
The HttpStatusCode is also OK. This problem occurs for only this URL. Is
there a special requirement in the WebRequest for URLs with query strings in
it?

"Michael McCarthy" wrote:

长度为空还是对象为空?来自webrequests的流程默认不允许搜索,所以它不知道手头的长度..如果你在获得流后在代码中放一个中断你应该能够
将鼠标悬停在流上并查看它是否为空,它不应该为空
除非它出错,但它可能不知道长度......
Jason Manfield写道:

Is the length empty or is the object empty? Streams from webrequests by
default dont allow seeking so it won''t know the length off hand.. if you
put a break in the code after it gets the stream you should be able to
hover over the stream and see if it''s null or not, it shouldn''t be null
unless it got an error, but it may not know the length...

Jason Manfield wrote:
对于某些网址
(例如 http://v3.espacenet.com/origdoc?DB=E...=WO2005028634) ,内容长度对于HttpWebResponse我得到请求.GetResponse在
为空。 response.GetResponseStream()也是空的。但是,我能够在浏览器中打开URL(URL地址保持不变;它没有被重定向)

这是代码片段:

HttpWebRequest req =(HttpWebRequest)WebRequest.Create(pageAddress);
HttpWebResponse resp =(HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream()) ;
string pageData = sr.ReadToEnd();

响应的内容类型是text / html;字符集= ISO-8859-1"并且
HttpStatusCode没问题。 pageData长度为0.

是否应修改URL以使其工作(例如某些替换)?

我缺少什么?

谢谢

杰森
For some URLs
(e.g.http://v3.espacenet.com/origdoc?DB=E...=WO2005028634),
the content length for the HttpWebResponse I get with request.GetResponse in
empty. The response.GetResponseStream() also empty. However, I am able to
open the URL in the browser (the URL address remains the same; it is not
redirected)

Here is the code snippet:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string pageData = sr.ReadToEnd();

The Content Type for the response is "text/html; charset=iso-8859-1" and the
HttpStatusCode was OK. The pageData length is 0.

Should the URL be modified for it to work (e.g. some substitution)?

What am I missing?

Thanks

Jason



这篇关于一些网址的空HttpWebResponse长度(带有查询?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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