This commit is contained in:
tongfei
2023-10-28 18:03:13 +08:00
parent 9bcd0e9600
commit 5c21be85ac

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.IO;
@@ -16,10 +17,12 @@ namespace WMS.Web.Core.Help
public class HttpClientHelp
{
private HttpOptions _options;
private ILogger<HttpClientHelp> _logger;
public HttpClientHelp(IOptions<HttpOptions> options)
public HttpClientHelp(IOptions<HttpOptions> options, ILogger<HttpClientHelp> logger)
{
this._options = options?.Value;
this._logger = logger;
}
public string PostHttp(string url, JsonObject reqData, bool isHaveCookie = false, string cookieValue = "", string appSecret = "")
{
@@ -84,6 +87,8 @@ namespace WMS.Web.Core.Help
public string PostHttp(string url, LoginAuthorizeRequest reqData)
{
_logger.LogInformation($"HttpPost->11111111111111111");
var str = string.Format("client_id={0}&client_secret={1}&grant_type={2}&username={3}&password={4}&scope={5}",
reqData.ClientId, reqData.ClientSecret, reqData.GrantType, reqData.UserName, reqData.Password,reqData.Scope);
ASCIIEncoding encoding = new ASCIIEncoding();
@@ -96,17 +101,19 @@ namespace WMS.Web.Core.Help
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(url);
httpClient.Timeout = new TimeSpan(0, 0, 10);
_logger.LogInformation($"HttpPost-2>"+ str);
HttpResponseMessage response = httpClient.PostAsync(url, httpContent).Result;
if (response.IsSuccessStatusCode)
{
var resData = response.Content.ReadAsStringAsync().Result;
_logger.LogInformation($"HttpPost-3>" + resData);
return resData;
}
else
{
var resData = response.Content.ReadAsStringAsync().Result;
_logger.LogInformation($"HttpPost-4>" + resData);
return resData;
}