I looked at this in some detail. I think the server is looking for a
User-Agent header in the request. If it finds one, it sends a response page.
Otherwise it doesnt.
You can take a look at the attached program. Set the proxy if needed. Run
the program with the UserAgent set. You will see the page getting
downloaded. Then rerun it with that line commented out. And the response
will have Zero content-length.
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
public class EP {
public static void Main(string [] args)
{
string us =
"http://v3.espacenet.com/origdoc?DB=EPODOC&IDX=WO2005028634&F=0&QPN=WO20050 28634";
HttpWebRequest req = WebRequest.Create(us) as HttpWebRequest;
req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.6)
Gecko/20";
//req.Proxy = new WebProxy("http://my-proxy");
try {
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
foreach(string h in resp.Headers) {
Console.WriteLine(h + ": " + resp.Headers[h]);
}
Stream rs = resp.GetResponseStream();
MemoryStream ms = new MemoryStream();
byte [] data = new byte[1024];
int read = rs.Read(data,0,data.Length);
while(read > 0) {
ms.Write(data,0,read);
read = rs.Read(data,0,data.Length);
}
resp.Close();
ms.Seek(0,SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms);
String s = sr.ReadToEnd();
sr.Close();
Console.WriteLine("====");
Console.WriteLine(s);
} catch(Exception e) {
Console.WriteLine(e);
}
}
}
--
feroze
-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.
See
http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------
"Jason Manfield" <Ja***********@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
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