C# http请求

奋斗吧
奋斗吧
擅长邻域:未填写

标签: C# http请求 .Net博客 51CTO博客

2023-05-24 18:24:13 201浏览

C# http请求, ///<summary>    ///GET方式发送得结果    ///</summary>    ///<paramname="url">请求的url</param> &

 /// <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;

       }

好博客就要一起分享哦!分享海报

此处可发布评论

评论(0展开评论

暂无评论,快来写一下吧

展开评论

您可能感兴趣的博客

客服QQ 1913284695