A GET method.
Using system.net; using system.text; using system.web; using msxml2; using system.threading;
namespace Engine.Activity.FeeAgency {///
Stream myStream = HttpWResp.GetResponseStream (); StreamReader sr = new StreamReader (myStream, Encoding.Default); StringBuilder strBuilder = new StringBuilder (); while (! -1 = sr.Peek ()) {strBuilder.Append (sr.ReadLine ());
Strresult = strbuilder.tostring ();} catch (exception exp) {strresult = "error:" Exp.Message;
Return Strresult;
}
}
Two POST methods can handle Chinese URL
Using system.net; using system.text; using system.web; using msxml2; using system.threading;
Namespace Engine.Activity.FeeAgency {public class postttp {private postttp () {} public static string post_http (string a_strull, string a_strpostdata) {string strresult = "
Try {encoding encoding = encoding.getencoding ("GB2312");
String postdata = a_strpostdata;
Strincel = a_strurl;
Byte [] data = encoding.getbytes (postData);
// Prepare request ...
Httpwebrequest myrequest = (httpwebRequest) WebRequest.create (Strurl);
MyRequest.Method = "post";
MyRequest.contentType = "Application / X-WWW-FORM-URLENCODED";
MyRequest.contentLength = data.length; stream newstream = myRequest.getRequestStream ();
// send data
Newstream.write (Data, 0, Data.Length); newstream.close ();
Try {httpwebresponse httpwresp = (httpwebresponse) MyRequest.getResponse ();
Stream myStream = HttpWResp.GetResponseStream (); StreamReader sr = new StreamReader (myStream, Encoding.Default); StringBuilder strBuilder = new StringBuilder (); while (! -1 = sr.Peek ()) {strBuilder.Append (sr.ReadLine ());
Strresult = strbuilder.tostring ();} catch (exception exp) {strresult = "error:" Exp.Message;
} CatCH (Exception Exp) {strresult = "Error:" Exp.Message;
Return Strresult;
}}}