http调用速度慢

m0_37360669 m0_37360669 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
string htp = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
jsonfh = HttpPost(htp, jsonText);

如果本地调用速度很快,但是放到服务器上,调用需要15秒才能返回结果

public static string HttpPost(string url, string postData)
{
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
byte[] data = Encoding.UTF8.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Proxy = null;
request.Method = "Post";
request.ContentType = "application/json";
request.ContentLength = data.Length;
request.KeepAlive = true;

Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);

HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
}

StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();

request.Abort();
response.Close();
reader.Dispose();
stream.Close();
stream.Dispose();

return content;
}
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
m0_37360669
C# 111,128 成员 642,536 内容