Files
Web_CRICS_Server_VS2010_Prod/CommonEntity/MyHttp.cs

55 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp;
using System.Net;
using Common;
namespace CommonEntity
{
public class MyHttp
{
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(MyHttp));
/// <summary>
/// 发送HTTP请求
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Url"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static string SendHttpData<T>(string Url, T obj)
{
try
{
var A = (SecurityProtocolType)48;
var B = (SecurityProtocolType)192;
var C = (SecurityProtocolType)768;
var D = (SecurityProtocolType)3072;
var E = (SecurityProtocolType)12288;
ServicePointManager.SecurityProtocol = A | B | C | D | E;
// 或者方法3使用所有现代TLS协议
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
var client1 = new RestClient(Url);
var request1 = new RestRequest("", Method.POST);
//var jsa= Newtonsoft.Json.JsonConvert.SerializeObject(obj);
request1.AddJsonBody(obj);
var QQQ = client1.Execute(request1);
HttpStatusCode HHH = QQQ.StatusCode;
string fanhuizhi = QQQ.Content;
return fanhuizhi;
}
catch (Exception ex)
{
//string Key = "HttpRequest_" + resp.code + "_" + resp.roomNumber;
//MemoryCacheHelper.Set(Key, 1, DateTimeOffset.Now.AddMinutes(10));
logger.Error("Fault Push Error:" + ex.Message);
logger.Error("Fault Push Error:" + ex.StackTrace);
return ex.Message;
}
}
}
}