添加项目文件。
This commit is contained in:
56
HT.Cloud.Code/Extend/Ext.RemoteHttpGet.cs
Normal file
56
HT.Cloud.Code/Extend/Ext.RemoteHttpGet.cs
Normal file
@ -0,0 +1,56 @@
|
||||
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
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user