WireMock.Net: Content-Type multipart/form-data is not serialized in proxy and recording mode
In the last version of WireMock.Net.StandAlone
( Version=“1.0.8”), when doing a Content-Type multipart/form-data POST request, the mapping generated doesn’t contain the Matcher for the body (so that don’t made it a valid mapping).
Note: I forward to another Wiremock instance and see the content of the body, so the content seems to be forwarded.
I get the generated mapping (Notice the empty “Body” key) :
{
"Guid": "ba19b8f6-432e-4e4b-92e0-d51c372b4277",
"Title": "",
"Priority": 0,
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/export/xxxxxx/upload",
"IgnoreCase": false
}
]
},
"Methods": [
"POST"
],
"Headers": [
{
"Name": "Content-Type",
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "multipart/form-data; boundary=\"31455f07-7487-400f-906e-9e1aefa04869\"",
"IgnoreCase": true
}
]
},
{
"Name": "Host",
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "localhost:8080",
"IgnoreCase": true
}
]
},
{
"Name": "Content-Length",
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "298",
"IgnoreCase": true
}
]
}
],
"Body": {}
},
"Response": {
"StatusCode": 404,
"BodyAsJson": {
"Status": "No matching mapping found"
},
"UseTransformer": false,
"Headers": {
"Content-Type": "application/json",
"Date": "Mon, 01 Apr 2019 10:09:04 GMT",
"Server": "Kestrel",
"Transfer-Encoding": "chunked"
}
}
}
I have the same behavior when doing the request through Postman or C# code…
If you want to test, you could reproduce with this code.
public async Task<T> UploadFileFromPath<T>(string uri, string filePath, string filename = null)
{
if (!File.Exists(filePath))
{
throw new ArgumentException($"The file to upload '{filePath}' doesn't exist!");
}
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
using (var form = new MultipartFormDataContent())
using (var sc = new StreamContent(fs))
{
sc.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
form.Add(sc, "file", filename ?? Path.GetFileName(filePath));
var response = await _httpClient.PostAsync(uri, form).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
return await HandleResponse<T>(response).ConfigureAwait(false);
}
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17
Today a new official NuGet will be released.