var postObj = new
{
FolderName = folderName,
FileName = fileName,
FileContent = fileContent
};
var postJson = JsonConvert.SerializeObject(postObj);
var responseJson = this.DoPostQuery(postJson, AppConfig.GetUploadFileUrl()).Result;
var responseObject = JsonConvert.DeserializeObject<NextResult>(responseJson);
if (responseObject == null)
{
BoLog.Instance.WriteErrorLog;
}
var fileId = 0;
if (responseObject.Data != null)
{
_ = int.TryParse(responseObject.Data.FileId.ToString(), out int _fileId);
if (_fileId <= 0)
{
BoLog.Instance.WriteErrorLog;
}
fileId = _fileId;
}
private async Task<string> DoPostQuery(string postJson, string url)
{
var baseUri = new Uri(url);
var handler = new HttpClientHandler
{
UseDefaultCredentials = true
};
if (baseUri.Scheme.ToLower() == "https")
{
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
}
var httpClient = new HttpClient(handler);
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "");
//httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", this.GetToken());
var response = await httpClient.PostAsync(url, new StringContent(postJson, Encoding.UTF8, "text/json"));
string responseJson = await response.Content.ReadAsStringAsync();
//var responseJson = BoRequest.Instance.GetHtml(url, postJson, "application/json;");
BoLog.Instance.WriteInfoLogDebug;
return responseJson;
}
Framework 调用https
最新推荐文章于 2024-11-03 15:22:04 发布