usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Net.Http;usingSystem.Threading.Tasks;usingSystem.Web;usingSystem.Text;usingNewtonsoft.Json;usingSystem.Net;namespaceesquel_LPD_Bot.LPDService
{public classGarmentStyleHelper
{public async Task GarmentStyleSearch(stringpi_GarmentStyleNo)
{string l_returnValue = string.Empty;string l_APIUrl = Common.ConfigHelper.GetConfigValue("LPD-GarmentStyleSearchAPIUrl");
Common.LPDAuthHelper LPDAuthClass= newCommon.LPDAuthHelper();try{if(string.IsNullOrEmpty( LPDAuthClass.UserName)|| string.IsNullOrEmpty(LPDAuthClass.UserName))
{throw new Exception("LPD Project Auth User Name Or Password Is Empty .");
}if (!string.IsNullOrEmpty(l_APIUrl) && !string.IsNullOrEmpty(pi_GarmentStyleNo))
{var request = newModel.SelectionFilter()
{
FilterType=Model.SelectionFilter.FilterTypeLeaf,
Filters= newModel.SelectionFilter[] { },
AttributeName= "item_number",
FilterValue=pi_GarmentStyleNo
};//--------------------------------------------------------------------------------------------
var handler = newHttpClientHandler()
{
AutomaticDecompression=System.Net.DecompressionMethods.GZip
};//handler.UseDefaultCredentials = true;//use default network利用的用户本机的网络,但因为需要布署到服务器,所以使用以下这一句
handler.Credentials=newNetworkCredential(LPDAuthClass.UserName, LPDAuthClass.PassWord);//设定权限,这一句比较痛苦,找了很久using (var client = newHttpClient(handler))
{
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));var response = await client.PostAsync(l_APIUrl, new StringContent(JsonConvert.SerializeObject(request).ToString(), Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();string l_getreturn = awaitresponse.Content.ReadAsStringAsync();
l_returnValue=l_getreturn;
}
}
}catch(Exception ex)
{
}returnl_returnValue;
}
}
}