javascript - How to make API call and pass header to it using Meteor -
i trying call 1 api using meteor. sample code given in api guide below:
request.headers.add("authorization", "basic " + convert.tobase64string(new asciiencoding().getbytes(username + password)));
i have use code in meteor, have not found solution yet. able call api has no header using both get
, post
method. how pass above header api call? using meteor.http.post
make api call. using following code referring above code:
return meteor.http.post("url", { headers: {"authorization": "basic"+(new buffer(username+password, "ascii")).tostring("base64")}, params: { name: username} } );
but it's not working. have working php code sample make api call:
$process = curl_init($host); curl_setopt($process, curlopt_httpheader, array('content-type: application/x-www-form-urlencoded', $additionalheaders)); curl_setopt($process, curlopt_header, 0); curl_setopt($process, curlopt_userpwd, $username . $password); curl_setopt($process, curlopt_timeout, 30); curl_setopt($process, curlopt_post, 1); curl_setopt($process, curlopt_postfields, $payloadname); curl_setopt($process, curlopt_returntransfer, true); $return = curl_exec($process); curl_close($process);
can give me hint how it? thank in advance.
callapi: function () { return meteor.http.post("url", { headers: {"authorization": "basic"+(new buffer(username+password, "ascii")).tostring("base64")}, params: { name: username} } ); }
using above code in server side code, can pass headers api.
Comments
Post a Comment