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;
}