HttpWebRequest Send HTTP Parameters

Source: Internet
Author: User

When using JS to send a request, the form is generally used. JSON object or string

$.post (URL,JSONSTR)

Server-side Get parameters

Request.QueryString.Get ();//Get parameter

Request.Form.Get ();//Post Parameters

Since has been the use of JS to send a request, did not pay attention to the server is not receiving parameters of the situation

When you use C # 's HttpWebRequest to send HTTP requests, you find that the server does not receive parameters. (appears when using post mode)

So use the most method, read InputStream, can get parameters

byte[] Byts = new Byte[this. Request.InputStream.Length];
Request.InputStream.Read (Byts, 0, Byts. Length);
JSON = System.Text.Encoding.Default.GetString (Byts);

If you want the server to get the form parameter Request.Form.Get () for the post, then pass the parameters as follows

String postpara="id=1&name=xx";//The same as the Parameter form on the URL

byte[] data = System.Text.Encoding.UTF8.GetBytes (Postpara);

Request. ContentLength = data. Length;

Reqstream = Request. GetRequestStream ();
Reqstream.write (data, 0, data. Length);
Reqstream.close ();

HttpWebRequest Send HTTP Parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.