我正在尝试发送帖子请求,但我遇到问题'远程服务器返回错误:(422)无法处理的实体。' ,我尝试了很多,但没有成功, 任何人都可以打电话给我,我的波纹管代码有什么问题。
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://url.com");
request.Method = "POST";
request.KeepAlive = false;
request.Accept = "application/json";
request.Headers.Add("Authorization", "Bearer e*******");
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
mobile_number = "9763641790",
first_name = "suraj",
last_name="mahajan"
});
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
答案 0 :(得分:0)
我不知道这段代码有什么问题,但是我尝试了bellow方法,并且它可以正常工作
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://url.com?mobile_number=9763641790&first_name=suraj&last_name=mahajan");
我通过网址发送数据。