You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http.Headers;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.QuarztJobs.Other
|
|
|
|
|
{
|
|
|
|
|
public class HttpHellp
|
|
|
|
|
{
|
|
|
|
|
private static readonly HttpClient _httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(60) };
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// post请求
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceAddress">请求地址</param>
|
|
|
|
|
/// <param name="requestJson">请求参数</param>
|
|
|
|
|
/// <param name="headers">请求头</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<string> PostAsync(string serviceAddress, string requestJson = null, Dictionary<string, string> headers = null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string result = string.Empty;
|
|
|
|
|
Uri postUrl = new Uri(serviceAddress);
|
|
|
|
|
|
|
|
|
|
using (HttpContent httpContent = new StringContent(requestJson))
|
|
|
|
|
{
|
|
|
|
|
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
|
|
|
|
if (headers != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var header in headers)
|
|
|
|
|
{
|
|
|
|
|
httpContent.Headers.Add(header.Key, header.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var response = await _httpClient.PostAsync(serviceAddress, httpContent);
|
|
|
|
|
|
|
|
|
|
result = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.Message);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|