1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- namespace IoTIntegrationPlatform.Common
- {
- /// <summary>
- /// http公共类
- /// </summary>
- public static class HttpHelper
- {
- /// <summary>
- /// post方法异步请求
- /// </summary>
- /// <param name="url">目标地址</param>
- /// <param name="json">发送的参数字符串</param>
- /// <returns></returns>
- public static async Task<string> PostAsync(string url, string json)
- {
- string responseBody = string.Empty;
- try
- {
- HttpClient client = new HttpClient(new HttpClientHandler() { UseCookies = false });
- var data = new StringContent(json, Encoding.UTF8, "application/json");
- HttpResponseMessage response = await client.PostAsync(url, data);
- response.EnsureSuccessStatusCode();
- responseBody = await response.Content.ReadAsStringAsync();
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return responseBody;
- }
- }
- }
|