我正在尝试向服务器发送POST请求。我使用.NET 4.5(从服务器获得OK)的代码可以正常工作但是使用Mono我得到一个WebException,说请求超时。
使用像HttpRequester这样的程序发送POST请求也对我有用,所以它不是服务器。我听说Mono没有TLS 1.1和TLS 1.2的实现,但我不知道这是不是问题。我使用相同的机器运行.NET(Visual Studio)和Mono。
的应用程序public static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback += (s, e, i, o) => true; // Trust all certificates (debug)
var url = "https://pgorelease.nianticlabs.com/plfe/rpc";
var requestData = "Hello World!";
var byteArray = Encoding.UTF8.GetBytes(requestData);
var request = (HttpWebRequest)WebRequest.Create(url);
request.Proxy = null;
request.UserAgent = "Niantic App";
request.Method = "POST";
request.KeepAlive = true;
request.Accept = "*/*";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.AllowAutoRedirect = false;
request.Expect = "200";
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.Timeout = 30000;
using (var stream = request.GetRequestStream())
{
stream.Write(byteArray, 0, byteArray.Length);
}
try
{
var response = (HttpWebResponse)request.GetResponse();
using (var stream = response.GetResponseStream())
{
// print response
}
}
catch (WebException ex)
{
// if response available print response, else print exception
}
Console.ReadLine();
}