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

本文关键字:返回 restclient 工作 WebClient Post 服务器 | 更新日期: 2023-09-27 18:01:28

这段代码返回一个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和高级休息客户端一切都是200与此URL作为POST

http://server: 8018/质量/serialnumber/BoxBuilds/999/高度/? SubAssemblySerialNumber = 555,参考的= 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());
}

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

谢谢Martin Parkin

is is working

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());
}
    WebClient wc = new WebClient();
                wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                wc.Encoding = System.Text.Encoding.UTF8;
                wc.UseDefaultCredentials = true;
                string cRresultData = wc.UploadString(URI, "POST", CRreq);
                //string cRresultData = wc.UploadString(URI,CRreq);
                string cRresponse = "";
this code gives me  500 Server error