简体   繁体   中英

HttpWebRequest only send Get requests and not post

im trying to send POST request using HttpWebRequest and fiddler shows me that im sending 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. 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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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