wiremock的文档说,多亏了这段代码,我们可以模拟一个检索文件的请求:
{ "request": { "method": "GET", "url": "/body-file" }, "response": { "status": 200, "bodyFileName": "path/to/myfile.xml" } }
但现在我必须找到一种真正上传文件的方法,否则我的请求会有500个错误。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 </title>
</head>
<body>
<h2>HTTP ERROR: 500</h2>
<p>Problem accessing /body-file. Reason:
<pre> java.lang.RuntimeException: java.io.FileNotFoundException: /wiremock-standalone/./__files/path/to/myfile.xml (No such file or directory)</pre>
</p>
<hr />
<i>
<small>Powered by Jetty://</small>
</i>
</body>
精度:由于我们的基础设施限制,我不能直接上传文件。
发布于 2018-10-31 00:00:11
最近的Wiremock版本具有管理存根文件的端点(请参阅https://github.com/tomakehurst/wiremock/blob/2.19.0/src/main/java/com/github/tomakehurst/wiremock/admin/AdminRoutes.java#L77)
您可以将带有PUT的文件上传到/__admin/files/{filename}。它们存储在${pwd}/__files下。
发布于 2018-05-01 07:17:45
一种解决方法是使用"body"参数,如下所示:
{
{
"request": {
"method": "GET",
"url": "/body-file"
},
"response": {
"status": 200,
"body": "<example><node Id='1' Action='Insert' /></example>"
}
}(请注意'1'和"1"中的单引号-您需要转义那些使用\"1\"的引号。
请参阅http://wiremock.org/docs/stubbing -指定响应正文部分。
如果您需要JSON有效负载,使用"jsonBody"参数会更好:
{
{
"request": {
"method": "GET",
"url": "/body-file"
},
"response": {
"status": 200,
"jsonBody":
{
"field1": "value1",
"field2" : "value2"
}
}
}另一个很好的特性是,引用:
已经创建的
存根映射可以通过在Java语言中调用
WireMock.saveAllMappings或向http://<host>:<port>/__admin/mappings/save发送一个带有空体的请求来持久化到映射目录中。
https://stackoverflow.com/questions/46316393
复制相似问题