CSharp - C# WebClient Post返回服务器返回 500,但restclient正在工作

  显示原文与译文双语对照的内容
0 0

这里代码返回 500


string URL ="http://" + MSSRestSrv +":8018/Quality/SerialNumbers/BoxBuilds/" + serial +"/Attach/";
string SubAssemblySerialNumber = form.serail;
string Refdes = row.Cells["RefDesc"].Value.ToString().Replace(";","");

try
{
 using (WebClient client = new WebClient())
 {
 System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
 reqparm.Add("SubAssemblySerialNumber", SubAssemblySerialNumber);
 reqparm.Add("Refdes", Refdes);
 byte[] responsebytes = client.UploadValues(URL,"POST", reqparm);
 string responsebody = Encoding.UTF8.GetString(responsebytes);
 }
}
catch (WebException we)
{
 MessageBox.Show(we.Response.ToString());
}

但是通过 Chrome 和高级Rest客户端,所有的内容都是 200,

http://server:8018/Quality/SerialNumbers/BoxBuilds/999/Attach/?SubAssemblySerialNumber=555&Refdes=SUB1

什么是不同的想法?

这工作正常


string SubAssemblySerialNumber = form.serail;
string Refdes = row.Cells["RefDesc"].Value.ToString().Replace(";","");
string URL ="http://" + MSSRestSrv +":8018/Quality/SerialNumbers/BoxBuilds/" + serial +"/Attach/?SubAssemblySerialNumber=" + SubAssemblySerialNumber +"&Refdes=" + Refdes +"";
try
{
 using (WebClient client = new WebClient())
 {
 System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();

 byte[] responsebytes = client.UploadValues(URL,"POST", reqparm);
 string responsebody = Encoding.UTF8.GetString(responsebytes);
 }
}
catch (WebException we)
{
 MessageBox.Show(we.Response.ToString());
}

时间: 原作者:

0 0

感谢 Martin Parkin

正在工作


string SubAssemblySerialNumber = form.serail;
string Refdes = row.Cells["RefDesc"].Value.ToString().Replace(";","");
string URL ="http://" + MSSRestSrv +":8018/Quality/SerialNumbers/BoxBuilds/" + serial +"/Attach/?SubAssemblySerialNumber=" + SubAssemblySerialNumber +"&Refdes=" + Refdes +"";
try
{
 using (WebClient client = new WebClient())
 {
 System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();

 byte[] responsebytes = client.UploadValues(URL,"POST", reqparm);
 string responsebody = Encoding.UTF8.GetString(responsebytes);
 }
}
catch (WebException we)
{
 MessageBox.Show(we.Response.ToString());
}

原作者:
...