Returned results of ASP. net post access to the internet interface

Source: Internet
Author: User
Code
String postdata = string. Format ("A = 1 & B = 2"); // post Parameters
Stream outstream = NULL;
Stream instream = NULL;
Streamreader sr = NULL;
Httpwebresponse response = NULL;
Httpwebrequest request = NULL;
Encoding encoding = encoding. default;
Byte [] DATA = encoding. getbytes (postdata );
// Prepare the request
Try
{
// Set parameters
Request = webrequest. Create ("http://www.bbb.com") as httpwebrequest;
Cookiecontainer = new cookiecontainer ();
Request. cookiecontainer = cookiecontainer;
Request. allowautoredirect = true;
Request. method = "Post ";
Request. contenttype = "application/X-WWW-form-urlencoded ";
Request. contentlength = data. length;
Outstream = request. getrequeststream ();
Outstream. Write (data, 0, Data. Length );
Outstream. Close ();
// Send the request and obtain the response data
Response = request. getresponse () as httpwebresponse;
// The POST request is not sent to the target webpage until the request. getresponse () program starts.
Instream = response. getresponsestream ();
Sr = new streamreader (instream, encoding );
// Return result webpage (HTML) Code
Return Sr. readtoend ();
}
Catch
{
Return NULL;
}
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.