Search code examples
httpasp.net-web-apifiddler

Make POST request with file and xml content


I am trying to make a POST request to an api server.

I have a request body which is an xml parameter:

<create-user>
    <user-name>username1</user-name>
    <password>password1</password>
</create-user>

Next to this parameter, i also need so send a file.

I've tried with fiddler the following thing, but the data is not received by the server (the file exists, but the <create-user> parameter not.

Is possible to send a combination of xml parameters with uploaded files?

enter image description here


Solution

  • Yes. Just add boundary mark (and "Content-Type: application/xml") before XML body. Like the following:

    ------yxz
    Content-Disposition: form-data; name="formInputXML"
    Content-Type: application/xml
    
    <create-user>...</create-user
    ------xyz
    Content-Disposition: form-data; name="formInputFile"; filename="UserData.xml"
    Content-Type: text/xml
    
    <UserData.xml content>
    ------xyz--