C# http请求
? ? ? ? /// <summary>
? ? ? ? /// GET方式發送得結果
? ? ? ? /// </summary>
? ? ? ? /// <param name="url">請求的url</param>
? ? ? ? public static string DoGetRequestSendData(string url)
? ? ? ? {
? ? ? ? ? ? HttpWebRequest hwRequest = null;
? ? ? ? ? ? HttpWebResponse hwResponse = null;
? ? ? ? ? ? string strResult = string.Empty;
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? hwRequest = (System.Net.HttpWebRequest)WebRequest.Create(url);
? ? ? ? ? ? ? ? //hwRequest.Timeout = 30000;
? ? ? ? ? ? ? ? hwRequest.Method = "GET";
? ? ? ? ? ? ? ? hwRequest.ContentType = "application/x-www-form-urlencoded";
? ? ? ? ? ? }
? ? ? ? ? ? catch (System.Exception err)
? ? ? ? ? ? {
? ? ? ? ? ? }
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? hwResponse = (HttpWebResponse)hwRequest.GetResponse();
? ? ? ? ? ? ? ? StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.ASCII);
? ? ? ? ? ? ? ? strResult = srReader.ReadToEnd();
? ? ? ? ? ? ? ? srReader.Close();
? ? ? ? ? ? ? ? hwResponse.Close();
? ? ? ? ? ? }
? ? ? ? ? ? catch (System.Exception err)
? ? ? ? ? ? {
? ? ? ? ? ? }
? ? ? ? ? ? return strResult;
? ? ? ? }
轉載于:https://www.cnblogs.com/jincieryi/p/9630054.html
總結
- 上一篇: 宏杉MacroSan存储开局指导-流程
- 下一篇: 重新记录一下微信后台的配置