11
This commit is contained in:
@@ -17,12 +17,12 @@ namespace BLL.Common
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static string HttpGetRequest(string url)
|
||||
public static string HttpGetRequest(string url, string token = "")
|
||||
{
|
||||
string strGetResponse = string.Empty;
|
||||
try
|
||||
{
|
||||
var getRequest = CreateHttpRequest(url,"", "GET");
|
||||
var getRequest = CreateHttpRequest(url, "GET", token);
|
||||
var getResponse = getRequest.GetResponse() as HttpWebResponse;
|
||||
strGetResponse = GetHttpResponse(getResponse, "GET");
|
||||
}
|
||||
@@ -48,7 +48,7 @@ namespace BLL.Common
|
||||
var postRequest = CreateHttpRequest(url, "POST",token, postJsonData);
|
||||
var postResponse = postRequest.GetResponse() as HttpWebResponse;
|
||||
strPostReponse = GetHttpResponse(postResponse, "POST");
|
||||
BLL.ErrLogInfo.WriteLog("result=" + strPostReponse);
|
||||
//BLL.ErrLogInfo.WriteLog("result=" + strPostReponse);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -99,24 +99,34 @@ namespace BLL.Common
|
||||
const string post = "POST";
|
||||
if (string.Equals(requestType, get, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
request = CreateGetHttpWebRequest(url);
|
||||
request = CreateGetHttpWebRequest(url, token);
|
||||
}
|
||||
if (string.Equals(requestType, post, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
request = CreatePostHttpWebRequest(url, strJson[0].ToString(),token);
|
||||
request = CreatePostHttpWebRequest(url, strJson[0].ToString(), token);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private static HttpWebRequest CreateGetHttpWebRequest(string url)
|
||||
private static HttpWebRequest CreateGetHttpWebRequest(string url, string token)
|
||||
{
|
||||
var getRequest = HttpWebRequest.Create(url) as HttpWebRequest;
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
getRequest.ContentType = "application/json";
|
||||
getRequest.Headers.Add("token", token);
|
||||
}
|
||||
else
|
||||
{
|
||||
getRequest.ContentType = "text/html;charset=UTF-8";
|
||||
}
|
||||
getRequest.Method = "GET";
|
||||
getRequest.Timeout = 5000;
|
||||
getRequest.ContentType = "text/html;charset=UTF-8";
|
||||
|
||||
getRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
||||
return getRequest;
|
||||
}
|
||||
|
||||
private static HttpWebRequest CreatePostHttpWebRequest(string url, string postData,string token)
|
||||
{
|
||||
var postRequest = HttpWebRequest.Create(url) as HttpWebRequest;
|
||||
|
||||
Reference in New Issue
Block a user