这段代码中的错误在哪里(c#HttpWebRequest)

时间:2012-12-10 16:56:56

标签: c# httpwebrequest

POST DATA =>

Accept:application/json, text/javascript, */*; q=0.01

Accept-Charset:ISO-8859-9,utf-8;q=0.7,*;q=0.3

Accept-Encoding:gzip,deflate,sdch

Accept-Language:tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4

Connection:keep-alive

Content-Length:0

Cookie:pfu=32904422; pfp=PO7PkdBDUwKoMG4FqkriwDLF7jrwcHBEoVqnX2i3; pfe=1386687638; 
logged_in=1; tmgioct=5hRBmncU3JQtInFOSa4qqoHX

Host:www.tumblr.com

Origin:http://www.tumblr.com

Referer:http://www.tumblr.com/customize/hayirasla?redirect_to=http%3A%2F%2Fhayirasla.tumblr.com%2F

User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11

X-Requested-With:XMLHttpRequest        

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";

        request.Headers.Add("Origin", "http://www.tumblr.com");
        request.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); //Bu üstbilgi uygun özellik veya yöntem kullanılarak değiştirilmelidir.
        request.Headers.Add(HttpRequestHeader.Cookie, "pfu=32904422;pfe=1386687638;pfp=PO7PkdBDUwKoMG4FqkriwDLF7jrwcHBEoVqnX2i3;logged_in=1;");
        return new StreamReader(((HttpWebResponse)request.GetResponse()).GetResponseStream()).ReadToEnd();

2 个答案:

答案 0 :(得分:1)

您无法通过 HttpWebRequest.Headers.Add()

添加标题

某些标头设置为限制

    private static readonly string[] RestrictedHeaders = new[]
        {
            "Accept", "Connection", "Content-Type", "Content-Length", "Date", "Expect", "Host", "Range", "Referer", "User-Agent"
        };

上面列出的所有标题都不能直接添加,只能使用

进行设置
//HttpWebRequest.[TheProperty] = value;

答案 1 :(得分:0)

你忘了“填写”后期数据?!?因为我看到你发送的请求只有标题......