Content-Type multipart/form-data is not serialized in proxy and recording mode
See original GitHub issueIn 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);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:17
Top Results From Across the Web
Why I can't upload file and send some other parameters ...
I need to upload a file with some other string type parameters, the content-type is multipart/form-data.And now the problem is I can make...
Read more >Consuming a REST API with a multipart or form data method
Whenever an API contains at least one method with its Request Format set to multipart/form-data, the RequestPart data structure is created.
Read more >File upload forms - HTTPie 3.2.2 (latest) docs
When uploading files, their content type is inferred from the file name. ... fields is present, the serialization and content type is multipart/form-data...
Read more >WireMock.Net/CHANGELOG and WireMock.Net Releases (Page 18 ...
Net' [feature]; #267 - Assembly does not have strong name ... #263 - Content-Type multipart/form-data is not serialized in proxy and recording mode...
Read more >http package - net/http
PostForm issues a POST to the specified URL, with data's keys and values URL-encoded as the request body. The Content-Type header is set...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Today a new official NuGet will be released.
@StefH I have tested it and it is working as expected.
Thank you very much!