Local IIS testing, Post calling interface, iispost Calling Interface

Source: Internet
Author: User

Local IIS testing, Post calling interface, iispost Calling Interface

I have recently learned three methods to call interfaces: POST, Socket, and Webserivce. I just wrote the POST method today, so I will share it with you. Thank you for your advice.

Public string strResult = "";
Protected void Page_Load (object sender, EventArgs e)
{
MyResponseList ("sent successfully ");
}
Public void MyResponseList (string Charset)
{


Try
{
ASCIIEncoding encoding = new ASCIIEncoding ();
Byte [] byteArray = encoding. GetBytes (Charset );
// The entry address can contain parameters.
HttpWebRequest webReq = (HttpWebRequest) WebRequest. Create (new Uri ("http: // 192.168.16.39: 808/Default. aspx? Num = 3 & name = broueli "));
WebReq. Method = "POST ";
WebReq. ContentType = "application/x-www-form-urlencoded ";
WebReq. ContentLength = byteArray. Length;

// Obtain the request object
Stream newStream = webReq. GetRequestStream ();
NewStream. Write (byteArray, 0, byteArray. Length); // Write Parameters
NewStream. Close ();
// Return Internet response
HttpWebResponse response = (HttpWebResponse) webReq. GetResponse ();
String encod = response. ContentEncoding;

// Determine whether the encoding method is obtained
If (encod = null | encod. Length <1)
{
Encod = "UTF-8 ";
}
// Read the stream. The stream is used to read the response body from the server. Encoding can be directly defined or obtained.
StreamReader sr = new StreamReader (response. GetResponseStream (), Encoding. GetEncoding (encod ));
// Read from the current position of the stream to the end
StrResult = sr. ReadToEnd ();
Sr. Close ();
Response. Close ();
NewStream. Close ();

}
Catch (Exception exp)
{

StrResult = "error:" + exp. Message;

}
}

Related Article

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.