Internal static string HttpPost (String Url, String postdatastr)
{
String retstring = String. Empty;
Try
{
HttpWebRequest request = (HttpWebRequest) webrequest.create (URL);
Request. Method = "POST";
Request. ContentType = "application/x-www-form-urlencoded";
Request. ContentLength = Encoding.UTF8.GetByteCount (POSTDATASTR);
if (!string. IsNullOrEmpty (WebProxy)))
{
WebProxy proxyobject = new WebProxy (WebProxy, Int32.Parse (WebProxyPort));
Proxyobject.credentials = new NetworkCredential (username, password, domain);
Request. Proxy = Proxyobject;
}
Log.infoformat ("username:{0};p Assword:{1};d omain:{2};webproxyport:{3}; URL:{4}; POSTDATA:{5} ", username,
Password, domain, WebProxyPort, Url, POSTDATASTR);
Log.infoformat ("username:{0};p Assword:{1};d omain:{2};webproxyport:{3}", username, password, domain, webproxyport);
Request. Cookiecontainer = cookie;
byte[] bytes = Encoding.UTF8.GetBytes (POSTDATASTR);
Stream Myrequeststream = Request. GetRequestStream ();
Myrequeststream.write (bytes, 0, bytes. Length);
Myrequeststream.close ();
HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
Response. Cookies = cookies. GetCookies (response. ResponseUri);
Stream Myresponsestream = Response. GetResponseStream ();
StreamReader Mystreamreader = new StreamReader (Myresponsestream, encoding.getencoding ("Utf-8"));
RetString = Mystreamreader.readtoend ();
Mystreamreader.close ();
Myresponsestream.close ();
Log. Info ("dopostsuccess" + retstring);
}
catch (Exception ex)
{
Log. Errorformat ("httppost_error! url:{0};p ostdatastr:{1},errormessage:{2} ", Url, Postdatastr, ex. Message);
}
return retstring;
}
<summary>
Send data by Get mode
</summary>
<param name= "Url" ></param>
<returns></returns>
public static string HttpGet (String Url)
{
HttpWebRequest request = (HttpWebRequest) webrequest.create (URL);
Request. Method = "GET";
Request. ContentType = "Text/html;charset=utf-8";
if (!string. IsNullOrEmpty (WebProxy)))
{
WebProxy proxyobject = new WebProxy (WebProxy, Int32.Parse (WebProxyPort));
Proxyobject.credentials = new NetworkCredential (username, password, domain);
Request. Proxy = Proxyobject;
}
HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
Stream Myresponsestream = Response. GetResponseStream ();
StreamReader Mystreamreader = new StreamReader (Myresponsestream, encoding.getencoding ("Utf-8"));
String retstring = Mystreamreader.readtoend ();
Mystreamreader.close ();
Myresponsestream.close ();
return retstring;
}
HttpGet and HttpPost requests