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 _options; public WebServiceAppService(IHttpClientFactory httpClientFactory, IOptions options) { _httpClientFactory = httpClientFactory; _options = options; } public Task> ReadAsync() { throw new NotImplementedException(); } /// /// /// /// /// public async Task 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"; } }