57 lines
1.1 KiB
C#
57 lines
1.1 KiB
C#
![]() |
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Net;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace HT.Cloud.Code
|
|||
|
{
|
|||
|
public class RemoteHttpRequest
|
|||
|
{
|
|||
|
#region Get请求
|
|||
|
/// <summary>
|
|||
|
/// HTTP GET方式请求数据.
|
|||
|
/// </summary>
|
|||
|
/// <param name="url">URL.</param>
|
|||
|
/// <returns></returns>
|
|||
|
public static string HttpGet(string url)
|
|||
|
{
|
|||
|
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
|
|||
|
request.Method = "GET";
|
|||
|
request.Accept = "*/*";
|
|||
|
request.Timeout = 15000;
|
|||
|
request.AllowAutoRedirect = false;
|
|||
|
|
|||
|
WebResponse response = null;
|
|||
|
string responseStr = null;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
response = request.GetResponse();
|
|||
|
|
|||
|
if (response != null)
|
|||
|
{
|
|||
|
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
|||
|
responseStr = reader.ReadToEnd();
|
|||
|
reader.Close();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
throw;
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
request = null;
|
|||
|
response = null;
|
|||
|
}
|
|||
|
|
|||
|
return responseStr;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|