接口文件
This commit is contained in:
69
Infrastructure/Hncore.Infrastructure/Common/HttpHelp.cs
Normal file
69
Infrastructure/Hncore.Infrastructure/Common/HttpHelp.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user