一直在寻找答案,似乎无法找到任何答案。我正在尝试使用Rest客户端从Windows窗体项目更新到Web服务。我已成功设法“GET”进入Datagridview,但我无法使用“POST”。以下是我尝试使用的代码片段(Generate License是一种将其写入xml文档并返回流的方法):
编辑:HttpResponse给了我这个错误:
<?xml version="1.0"?>
<Licenses_table><Licenses><ErrorCode>HY000</ErrorCode><DriverCode>1364</DriverCode><Message>Field 'Code' doesn't have a default value</Message></Licenses></Licenses_table>
string Url = "http://localhost:8810/ReplicationService.php/Licenses/";
byte[] dataByte = GenerateLicense(Code, Version1, Name);
HttpWebRequest POSTrequest = (HttpWebRequest)WebRequest.Create(Url);
POSTrequest.Method = "POST";
POSTrequest.ContentType = "text/xml";
POSTrequest.KeepAlive = false;
POSTrequest.Timeout = 5000;
POSTrequest.ContentLength = dataByte.Length;
Stream POSTstream = POSTrequest.GetRequestStream();
POSTstream.Write(dataByte, 0, dataByte.Length);
答案 0 :(得分:0)
这是您展示的整个代码吗?我没有看到您关闭请求流的位置,然后在WebRequest上调用GetResponse()?