/// <summary>
/// httpclient请求
/// </summary>
/// <param name="client"></param>
/// <param name="url"></param>
/// <param name="mobile"></param>
/// <param name="content"></param>
/// <returns></returns>
public string HttpRequest(HttpClient client, string url, string mobile, string content)
{
var req = new HttpRequestMessage();
req.Headers.Clear();
req.Headers.Add("ContentType", "application/x-www-form-urlencoded;charset=utf-8");
req.Method = HttpMethod.Post;
Dictionary<string, string> paras = new Dictionary<string, string>();
paras.Add("action", "send");
paras.Add("account", this.config.Account.UserName);
paras.Add("password", this.config.Account.Password);
paras.Add("mobile", mobile);
paras.Add("content", content);
req.Content = new FormUrlEncodedContent(paras);
req.RequestUri = new Uri(url);
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
var response = client.SendAsync(req).Result;
try
{
response.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
Trace.TraceError("Error:{0}", ex.Message);
return "";
}
return response.Content.ReadAsStringAsync().Result;
}
private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}