question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Content-Type multipart/form-data is not serialized in proxy and recording mode

See original GitHub issue

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);
            }
        }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17

github_iconTop GitHub Comments

1reaction
StefHcommented, Apr 5, 2019

Today a new official NuGet will be released.

0reactions
pmiosseccommented, Apr 5, 2019

@StefH I have tested it and it is working as expected.

Thank you very much!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found