如何模拟.NET HTTP响应?
我正在开发一个C#.NET框架应用程序,该应用程序必须从JSON格式中的不同设备中解析状态协议。 这些协议是通过HTTP请求(System.net.Webrequest和.Response)获得的。我没有机会直接从设备接收这些协议,但是我有技术规范。因此,我需要模拟响应。 我该如何测试:我需要一个URL,可以在其中存储JSON数据,以及可以接收并将这些数据加载到Applicaton的地方。
I’m developing a C# .NET Framework application which has to parse status protocols from different devices in the JSON format.
These protocols are obtained via http requests (System.Net.WebRequest and .Response). I don’t have the opportunity to receive these protocols directly from the devices, but I have a technical specification. So I need to simulate the response.
How can I test this: I need a URL where I can store my JSON data and from where I can receive and load this data into my applicaton.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以只读取从文件中的jsons来“模拟”响应。如果您想制作HTTP重新要求,则必须使用模拟的API。为此,您可以尝试 Mocky 。只需单击
网站上的新模拟
,然后创建自定义模拟的API即可。您将获得一个URL,可以使用您配置的标头和数据响应。You can just read the JSONs from a file(s) to "simulate" a response. If you want to make HTTP-Requests then you have to use a mocked API. For this purpose you can try Mocky. Just click on
NEW MOCK
on the website and create your custom mocked API. You will get an URL that will response with the headers and data that you configured.