有问题: 当使用HttpWebRequest服务器发送PUT请求时,始终返回415错误, 在Fiddler标头“ Content-Type”中,出现值“ application / json”,而不是全部 一定可以。但是在此代码的.NET变体中,所有操作都很好,这是我的错误,代码示例如下。在POSTMAN中一切正常 提前谢谢。
url := 'url';
body := '{"status": "NEW_STATUS"}';
NetCcredentials := NetCcredentials.NetworkCredential('login', 'password');
HttpWebRequest := HttpWebRequest.Create(url);
HttpWebRequest.Method := 'PUT';
HttpWebRequest.ContentType := 'application/json; charset=utf8';
HttpWebRequest.Timeout := 6000;
HttpWebRequest.Credentials := NetCcredentials;
HttpWebRequest.KeepAlive := TRUE;
RequestStr := HttpWebRequest.GetRequestStream;
StreamWriter := StreamWriter.StreamWriter(RequestStr,Encoding.UTF8);
StreamWriter.Write(body);
StreamWriter.Flush;
StreamWriter.Close;
StreamWriter.Dispose;
HttpWebResponse:=HttpWebRequest.GetResponse;
MESSAGE(HttpWebResponse.StatusCode.ToString);