我可以从我的api获取,但我无法发帖。它适用于邮递员。所以服务器没有问题。 我检查过三种方式:httpclient,httpwebrequest,webclient,但不适用于我:
1:
string data = "Name=mohammadi&BirthDate=1382-01-01&IsMarried=false&PersonId=16";
var client = new HttpClient();
var stringContent = new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded");
var s = await client.PostAsync(url, stringContent);
var content = s.Result;
内容说:“内部服务器错误”并且没有异常抛出
2:
string data = "Name=mohammadi&BirthDate=1382-01-01&IsMarried=false&PersonId=16";
WebClient w = new WebClient();
var str = w.OpenWrite(url, "POST");
w.Headers.Set(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
var writer = new StreamWriter(str);
writer.Write(data);
writer.Flush();
不起作用,什么都不说
3:
string data = "Name=mohammadi&BirthDate=1382-01-01&IsMarried=false&PersonId=16";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
var stream = await request.GetRequestStreamAsync();
using (var writer = new StreamWriter(stream))
{
writer.Write(data);
writer.Flush();
writer.Dispose();
}
stream.Dispose();
不起作用,什么都不说