简体   繁体   English

HttpWebRequest仅发送Get请求,而不发布

[英]HttpWebRequest only send Get requests and not post

im trying to send POST request using HttpWebRequest and fiddler shows me that im sending GET? 我试图使用HttpWebRequest发送POST请求,而小提琴手告诉我我正在发送GET吗? any help will be appreciated since im able to see what im doing wrong. 任何帮助将不胜感激,因为我能够看到自己做错了什么。

code : 代码:

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();

ok found the problem, the url im sending the request to is http://domain.com and when i send it to http://www.domain.com it works and send a post. 确定发现了问题,将请求发送到的网址是http://domain.com ,当我将其发送到http://www.domain.com时,它可以工作并发送帖子。 so new question why is that? 那么新的问题是为什么呢? ( the answer will get the answer to my question as i dont like the idea of voting my self ) (由于我不喜欢自己投票,因此答案将得到我问题的答案)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM