You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
2.5 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using StackExchange.Redis;
using Volo.Abp.Application.Services;
using Win_in.Sfs.Wms.DataExchange.Domain;
using Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent;
using static Volo.Abp.Identity.Settings.IdentitySettingNames;
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.InjectionMoldingTaskAgent.Client;
public class WebServiceAppService : IReader
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IOptions<InjectionMoldingTaskOptions> _options;
public WebServiceAppService(IHttpClientFactory httpClientFactory, IOptions<InjectionMoldingTaskOptions> options)
{
_httpClientFactory = httpClientFactory;
_options = options;
}
public Task<List<IncomingFromExternal>> ReadAsync()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="p_type"></param>
/// <returns></returns>
public async Task<string> WebApi(int p_type)
{
//var client = _httpClientFactory.CreateClient();
//// 设置用户名和密码
//var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"));
//client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials);
//// 发送HTTP请求
//var response = await client.GetAsync("https://example.com/api/data");
//if (response.IsSuccessStatusCode)
//{
// return await response.Content.ReadAsStringAsync();
//}
// SoapClient
var address = _options.Value.AutoRemote.IpAddress;
var username = _options.Value.AutoRemote.UserName;
var password=_options.Value.AutoRemote.Password;
var token= _options.Value.AutoRemote.Token;
var client = _httpClientFactory.CreateClient();
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials);
var response = await client.GetAsync("https://example.com/api/data").ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync();
}
return "Error occurred";
}
}