A simple method of asp.net post to get data flow--practical skills

Source: Internet
Author: User

Recently on the platform of some third party, often call the third party interface to implement some specific functions

In the implementation of the same time basically need local data through the server in the request to the third party server processing, and then return the corresponding data structure body: json/xml

Here is a small method that I have summed up, asking farmers to consultation fee:

public static string Postwebreq (String PostURL, String paramdata, Encoding dataencode) {string ret = string.
      Empty;
        try {byte[] ByteArray = dataencode.getbytes (Paramdata);
        HttpWebRequest Webreq = (HttpWebRequest) webrequest.create (new Uri (PostURL));
        Webreq.method = "POST";
        Webreq.contenttype = "application/x-www-form-urlencoded";

        Webreq.contentlength = Bytearray.length;
        Stream newstream = Webreq.getrequeststream ();
        Newstream.write (ByteArray, 0, bytearray.length);

        Newstream.close ();
        HttpWebResponse response = (HttpWebResponse) webreq.getresponse (); StreamReader sr = new StreamReader (response.
        GetResponseStream (), Dataencode); ret = Sr.

        ReadToEnd (); Sr.
        Close (); Response.
        Close ();
      Newstream.close (); The catch (WebException ex) {Log.writelog (Logfile.error, ex).
      message); finally {Log.writelog (Logfile.info,RET);
    return ret;
 }

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.