开发者

C# Sending an HttpWebRequest without the servername

开发者 https://www.devze.com 2023-04-01 21:03 出处:网络
Basically what I\'ve been trying to do is download a file off a server. The server sends a redirect automatically which is fine, but through packet sniffing a program that does successfully download t

Basically what I've been trying to do is download a file off a server. The server sends a redirect automatically which is fine, but through packet sniffing a program that does successfully download the file I've found that the Headers (for the second request) are:

GET /path/to/file.txt
...
Host: server.com

Rather than the current response being generated (what I thought was standard):

GET www.server.com/path/to/file.txt

Using the normal HttpWebRequest method results in a 500 server error, and I get exceptions thrown when 开发者_高级运维trying to use just the relative path as one would expect. Using AllowAutoRedirect does not work for this scenario as the cookies are not handled properly, but even if I handle it manually the same error occurs.

How does one go about doing this (preferably without sockets :D)?


To be honest, I'm really not sure what you are asking, but you mentioned cookie troubles. As a total shot in the dark guess, are you setting the CookieContainer on your WebRequest?

request.CookieContainer = new CookieContainer();
request.AllowAutoRedirect = true;
0

精彩评论

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