#How do I remove WebkitFormBoundary from a API call with formdata in it?

1 messages · Page 1 of 1 (latest)

tender kayak
#

FormData:

It uses the same format a form would use if the encoding type were set to "multipart/form-data".
https://developer.mozilla.org/en-US/docs/Web/API/FormData
So you are are lying to the server about the encoding by manually specifying application/x-www-form-urlencoded Content-Type and then giving the .post() method a data structure that will be multipart/form-data (which is what the boundaries are ------WebKitFormBoundaryYuIoxRtV7SIIOnCs)

#

See the next paragraph in the link:

You can also pass it directly to the URLSearchParams constructor if you want to generate query parameters in the way a <form> would do if it were using simple GET submission.

#

But the real question is... why are you manually mucking about with Content-Type instead of just letting the framework figure it out? IMPO setting Content-Type is frequently a code smell to be avoided.

jaunty python
#

@tender kayak not passing anything has same result.. had tried it before

APICall(data1: string, data2: string): Observable<any> {
    const url = `https://{{URL}}/api/update`;

    const formdata = new FormData();

    formdata.append('user', `${data1}`);
    formdata.append('dataType', `${data2}`);



    return this.http.post(url, formdata);
  }

In browser it is seen as

content-type: text/html;charset=utf-8

Payload is seen as

------WebKitFormBoundaryYuIoxRtV7SIIOnCs
Content-Disposition: form-data; name="user"

{{data1}}
------WebKitFormBoundaryYuIoxRtV7SIIOnCs
Content-Disposition: form-data; name="dataType"

{{data2}}
------WebKitFormBoundaryYuIoxRtV7SIIOnCs--
tender kayak
#

Because using FormData as a payload results in ------WebKitFormBoundaryYuIoxRtV7SIIOnCs in the request body. That is just how it works. If you don't want to use multipart/form-data encoding then don't use FormData.