I have the following cURL command:
// original curl
curl https://example.com \
-F "id=id" \
-F "secret=secret"
which I thought can be represented with this fetch
expression:
// fetch
const body = new FormData();
body.append('id', 'id');
body.append('secret', 'secret');
return fetch('https://example.com', {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'multipart/form-data',
},
body,
})
And then, copying the fetch request as cURL generates the following command:
// generated curl
curl 'https://example.com' \
-H 'content-type: multipart/form-data' \
--data-raw $'------WebKitFormBoundaryH2Ve4S1AUbboJ21W\r\nContent-Disposition: form-data; name="id"\r\n\r\nid\r\n------WebKitFormBoundaryH2Ve4S1AUbboJ21W\r\nContent-Disposition: form-data; name="secret"\r\n\r\nsecret\r\n------WebKitFormBoundaryH2Ve4S1AUbboJ21W--\r\n' \
--compressed
To my surprise, when using real data instead of placeholder data for the endpoint and form values, the original curl request works, but the generated curl request does not (nor does the fetch version).
Is there something obvious that I'm missing? What is the difference between the original cURL command and the fetch expression / generated cURL command?