且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

远程服务器返回错误:(500)内部服务器错误。

更新时间:2022-02-02 01:55:07

由于web api方法签名与web请求对象发送的参数不匹配,因此收到500错误。



您需要将此人详细信息发送到web api方法。您可以使用



You are getting 500 error because web api method signature is not matching with the arguments sent by web request object.

You need to send the person details to the web api method. You can use

var request = (HttpWebRequest)WebRequest.Create("http://23.92.223.177:8888/api/Contact/AddContact");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "Here you can set JSON data..";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();

byte[] byteArray = Encoding.UTF8.GetBytes (postData);





有关详细信息,请查看 c# - 如何使用WebRequest来发布一些数据并读取响应? - 堆栈溢出 [ ^ ]