在集成测试中使用测试服务器和HttpWebRequest调用AspNetCore Api

我正在尝试使用AspnetCore.TestHost.TestServer

调用AspNetCore API。

它与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吗?

macrosl 回答:在集成测试中使用测试服务器和HttpWebRequest调用AspNetCore Api

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3142969.html

大家都在问