none
Socket HTTP Post 获取不到任何数据 RRS feed

  • 问题

  • POST /maxwell-house-international-cafe-style-beverage-mix-hazelnut-cafe/qxp306609?catid=184312 HTTP/1.1
    Accept: text/html,application/xhtml+xml,application/xml, */*
    Referer: http://www.drugstore.com/maxwell-house-international-cafe-style-beverage-mix-hazelnut-cafe/qxp306609?catid=184312
    Accept-Language: zh-CN
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0
    Host: www.drugstore.com
    Connection: Keep-Alive
    Cache-Control: no-cache
    Accept-Encoding: gzip, deflate
    DNT: 1
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 112
     
    btnGroupDistn=Dark+Mayan+Chocolate+Latte&size=9&CSRFToken=s5jeYrXfkn7cDlo9vba%2fD8IwCFhQiDGv%2bHC1BmCQ%2f%2bw%3d




    请问这个post 请求有什么问题吗? 怎么获取不到数据呢?
    2014年12月27日 17:37

答案

  • 你好:

    你是想通过C#程序来向www.drugstore.com发送请求获取一些数据是吧?我建议你使用HttpWebRequest或者WebClient来发送请求,而不是直接使用Socket类。比如以下代码使用WebClient类可以成功获取到数据:

    WebClient client = new WebClient();
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                string url = @"http://www.drugstore.com/maxwell-house-international-cafe-style-beverage-mix-hazelnut-cafe/qxp306609?catid=184312";
                using (Stream data = client.OpenRead(url))
                {
                    using (StreamReader reader = new StreamReader(data))
                    {
                        string s = reader.ReadToEnd();
                        Console.WriteLine(s);
                    }
                }

    HttpWebRequest也是一样的。如果你坚持要使用Socket的话,有可能是你的程序没有发送成功,或者没有接收成功,具体要分析你的代码才能知道。


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年12月29日 3:12
    版主