我正在尝试使用AspnetCore.TestHost.TestServer
它与AspnetCore.TestHost.RequestBuilder
一起很好地工作,但是我想使用HttpWebRequest来调用它。
我尝试使用以下代码调用它:
网络请求
var httpWebRequest = (HttpWebRequest) System.Net.WebRequest.Create(testServer.BaseAddress + "api/employee");
httpWebRequest.AllowWriteStreamBuffering = allowWriteStreamBuffering;
httpWebRequest.Method = HttpConstants.HttpMethods.Post;
httpWebRequest.ContentType = contentType;
... some other settings
网络响应
using (var responseApi = (Httpwebresponse)httpWebRequest.GetResponse())
{
}
但是,我得到System.Net.WebException:'远程服务器返回错误:(404)未找到。'错误
有人可以帮助我知道如何使用测试服务器和HttpWebRequest调用api吗?