Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 远程服务器返回错误500内部服务器错误_C#_Asp.net_Web Services_Httpwebrequest - Fatal编程技术网

C# 远程服务器返回错误500内部服务器错误

C# 远程服务器返回错误500内部服务器错误,c#,asp.net,web-services,httpwebrequest,C#,Asp.net,Web Services,Httpwebrequest,我必须调用web服务的一个方法,该方法包含数组作为参数的一部分。 我不想为数组类型的参数传递任何值。 我尝试传递null“”(空),但web方法调用返回“远程服务器返回错误500内部服务器错误”作为错误。我无法找出原因?需要帮助。 这是我的密码 string post_data = "SessionID=" + sessionID + "&From=" + "" + "&To=" + "" + "&Changed=" + "" ; // this is where we

我必须调用web服务的一个方法,该方法包含数组作为参数的一部分。 我不想为数组类型的参数传递任何值。 我尝试传递null“”(空),但web方法调用返回“远程服务器返回错误500内部服务器错误”作为错误。我无法找出原因?需要帮助。 这是我的密码

string post_data = "SessionID=" + sessionID + "&From=" + "" + "&To=" + "" + "&Changed=" + "" ;

// this is where we will send it
string uri = "test.asmx";

// create a request
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(uri);
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";

// turn our request string into a byte stream
byte[] postBytes = Encoding.ASCII.GetBytes(post_data);

// this is important - make sure you specify type this way
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();

// now send it
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();

// grab te response and print it out to the console along with the status code
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
Console.WriteLine(response.StatusCode);

对于数组参数,而不是发送空字符串(“”),将其值作为
null
和request.ContentType应为“application/x-www-form-urlencoded”,而不是“application/soap+xml;charset=utf-8”,启用远程调试并在此处添加服务器错误感谢您的快速回复此建议似乎有效!您想指出的任何其他事项是否确定服务可以处理null参数?如果我添加服务引用并通过传递null参数调用方法,则服务返回响应,但当我尝试使用SOAP或简单httpwebrequest时,它返回“远程服务器返回错误500内部服务器错误”。