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

时间:2016-12-26 14:25:45

标签: c# asp.net web-services httpwebrequest

我必须调用一个Web服务方法,该方法包含数组作为参数的一部分。 我不想为Array类型的参数传递任何值。                 我尝试传递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);

0 个答案:

没有答案
相关问题