我正在尝试通过客户端的控制台从我的主项目中调用控制器上的方法。尝试将 putdata 发送到控制器。
这是我尝试过的
case "6": //PUT data (Data Controller) must already exist...
Console.WriteLine("Please enter the ID of the song to be uploaded");
string putdata = Console.ReadLine();
//request for method url in WEBSITE B
var request = (HttpWebRequest)WebRequest.Create("http://localhost:61381/DataController/Put");
var data = Encoding.ASCII.GetBytes(putdata);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response5 = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response5.GetResponseStream()).ReadToEnd();
break;
}
错误在请求中,抛出空异常。找不到控制器,我不确定如何正确指出这一点。