HttpWebRequest只发送Get请求而不发帖

时间:2013-10-29 14:21:04

标签: c# asp.net http

即时尝试使用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();

1 个答案:

答案 0 :(得分:0)

确定发现了问题,我发送请求的网址是http://domain.com,当我将其发送到http://www.domain.com时,它可以发送并发送帖子。所以新问题为什么会这样? (答案将得到我的问题的答案,因为我不喜欢投票给自己的想法)