0

我试图使用 HttpWebRequest 发送 POST 请求,fiddler 告诉我我正在发送 GET?任何帮助将不胜感激,因为我能够看到我做错了什么。

代码 :

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(LOGIN_API_BASE_URL);
        string postString = string.Format("api_email={0}&api_password={1}", EMAIL, PASSWORD);
        ASCIIEncoding encoding = new ASCIIEncoding();
        byte[] data = encoding.GetBytes(postString);
        CookieContainer cookies = new CookieContainer();
        request.CookieContainer = cookies;
        //request.AllowWriteStreamBuffering = true;
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = data.Length;
        request.Timeout = i_timeout;
        //request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
        //request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        //request.Referer = "https://accounts.craigslist.org";

        using (Stream writer  = request.GetRequestStream())
        {
            writer.Write(data, 0, data.Length);
            //writer.Close();
        }

        StreamReader responseReader = new StreamReader(request.GetResponse().GetResponseStream());
        string responseData = responseReader.ReadToEnd();

        responseReader.Close();
        request.GetResponse().Close();
4

1 回答 1

0

好的,找到了问题,我发送请求的 url 是http://domain.com,当我将它发送到http://www.domain.com时,它可以工作并发送一个帖子。这么新的问题为什么会这样?(答案将得到我问题的答案,因为我不喜欢自己投票的想法)

于 2013-10-29T14:26:17.580 回答