70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Net;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace Hncore.Infrastructure.Common
|
|||
|
|
{
|
|||
|
|
public static class HttpHelp
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// get请求
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="url"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string HttpGet(string url)
|
|||
|
|
{
|
|||
|
|
string result = string.Empty;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create(url);
|
|||
|
|
wbRequest.Method = "GET";
|
|||
|
|
HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();
|
|||
|
|
using (Stream responseStream = wbResponse.GetResponseStream())
|
|||
|
|
{
|
|||
|
|
using (StreamReader sReader = new StreamReader(responseStream))
|
|||
|
|
{
|
|||
|
|
result = sReader.ReadToEnd();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch/* (Exception ex) 此处暂时屏蔽掉了,要不然编译光弹出变量未使用的警告,谁用得着再打开*/
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// get 请求,带token
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="token"></param>
|
|||
|
|
/// <param name="url"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string HttpGet(string token,string url)
|
|||
|
|
{
|
|||
|
|
string result = string.Empty;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
HttpWebRequest wbRequest = (HttpWebRequest)WebRequest.Create(url);
|
|||
|
|
wbRequest.Headers.Add("token", token);
|
|||
|
|
wbRequest.Method = "GET";
|
|||
|
|
HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();
|
|||
|
|
using (Stream responseStream = wbResponse.GetResponseStream())
|
|||
|
|
{
|
|||
|
|
using (StreamReader sReader = new StreamReader(responseStream))
|
|||
|
|
{
|
|||
|
|
result = sReader.ReadToEnd();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch/* (Exception ex) 此处暂时屏蔽掉了,要不然编译光弹出变量未使用的警告,谁用得着再打开*/
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|