首页 > 代码库 > post,get
post,get
public static string SendGet(string url)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.Method = "GET";
HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
Stream stream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);
string strOut = streamReader.ReadToEnd();
httpWebResponse.Close();
strOut = HttpUtility.UrlDecode(strOut);
return strOut;
}
public static Stream SendGetForStream(string url)
{
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
request.Method = "GET";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream stream = response.GetResponseStream();
return stream;
}
public static string SendPost(string data, string url, string contentType)
{
string content = string.Empty;
HttpWebRequest httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = contentType;
using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()))
{
sw.Write(data);
}
HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream()))
{
content = sr.ReadToEnd();
}
return content;
}
public static void LoadPicFromStream(string url)
{
string content = string.Empty;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("");
request.Method = "GET";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream stream = response.GetResponseStream();
Image image = Image.FromStream(stream);
image.Save("", System.Drawing.Imaging.ImageFormat.Jpeg);
}
post,get