Only if you know what's the meaning ... google is your friend
代码:
public static string HTTP_POST(string Url, string Data, string Cookie, string ContentType)
{
string Out = String.Empty;
System.Net.HttpWebRequest req = System.Net.HttpWebRequest.Create(Url) as System.Net.HttpWebRequest;
try
{
req.Method = "POST";
req.Timeout = 100000;
req.ContentType = ContentType; //something like "multipart/form-data; boundary= xxxxxxxxxxx";
req.UserAgent = "Safari/537.36";
req.CookieContainer = new CookieContainer();
req.CookieContainer.Add(new Uri("http://www.google.com"), GetCookieCollectionFromCookieString(Cookie)); // <-- replace the Uri of your own target
req.Headers.Add("Accept-Encoding", "gzip,deflate");
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
byte[] sentData = Encoding.UTF8.GetBytes(Data); // <-- change your encoding if you want to publish different content
req.ContentLength = sentData.Length;
using (System.IO.Stream sendStream = req.GetRequestStream())
{
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
}
System.Net.WebResponse res = req.GetResponse();
System.IO.Stream ReceiveStream = res.GetResponseStream();
using (System.IO.StreamReader sr = new System.IO.StreamReader(ReceiveStream, Encoding.UTF8)) //<-- change encoding if you know the website's encoding method
{
Char[] read = new Char[256];
int count = sr.Read(read, 0, 256);
while (count > 0)
{
String str = new String(read, 0, count);
Out += str;
count = sr.Read(read, 0, 256);
}
}
}
catch (ArgumentException ex)
{
Out = string.Format("HTTP_ERROR :: The second HttpWebRequest object has raised an Argument Exception as 'Connection' Property is set to 'Close' :: {0}", ex.Message);
}
catch (WebException ex)
{
Out = string.Format("HTTP_ERROR :: WebException raised! :: {0}", ex.Message);
}
catch (Exception ex)
{
Out = string.Format("HTTP_ERROR :: Exception raised! :: {0}", ex.Message);
}