我的控制器中有一个接受字符串数组的方法:
public async Task<HttpResponseMessage> PostData(string[] data)
我想使用控制台应用程序向我的api发送请求,但我得到了404响应并且没有到达控制器:
WebRequest request = WebRequest.Create("http://localhost:1119/api/psr");
request.Method = "POST";
string num= "[ \"89\",\"21\" , \"2A,\" ]";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(num);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
WebResponse response = request.GetResponse();