We have a client API call for which it must be sent as a post form-data. When we run calls via Chrome's Postman Extension, we specify form-data, and if we specify the x-www-form-urlxod, then it is executed successfully by returning an error. This is expected.
However, when we try to run the "request" NPM package to handle the post, we will continue to get an error message from the API, which is unfortunate to us. Do not direct us from what is wrong. But we see that when requested that the requested title item looks like this:
_header: 'POST / API / client / coupon / add HTTP / 1.1 \ r \ n authorization : Original [auth string redacted] \ r \ nhost: beta1.client.com \ r \ ncontent-type: application / x-www-form-urlencoded \ r \ n Content-Length: 172 \ r \ n Connection: Alive \ r \ n \ r \ n ',
our node. Js code looks like this:
// create coupon code coupon = {code: "abcde1234"), discount: "33", type: "percent"} var request = requirement ('request '); Request.post ({url: "https://beta1.client.com/api/coupon/add", header: {"authorization": auth, "content-disposition": "form-data; name = 'data' "}, Form: coupon}, function (error, feedback, body) {if (! Error and response.statusCode == 200) {console.log (body)}});
Am I wondering why content-type header continues to read "application / x-www-form-url encode" when we have the content of 'form-data' The arrangement is provided. I feel that if I can remove the content type header, then it should work - but how to do it?
Any insights will be appreciated.
content-type
header application / x-www- Form-urlencoded
because you are using form
in your post request.
request.post ({url: "https://beta1.client.com/api/ coupon / add", header: {"authorization": auth, "content-disposition": "Form-data; name = 'data'"}, form: coupon}, function (error, response, body) {...});
To control it, you must add content as body
as given below.
request.post ({Url: "https://beta1.client.com/api/coupon/add", header: {"authorization": auth, "content-disposition": "Form-data; name = 'data'"}, body: coupon}, function (error, reaction, body) {...});
No comments:
Post a Comment