I'm trying send a request in Ionic using @angular/http
By side on the server (nodejs) I'm print the req.header
When request is via PHP/Postman/curl/Ionic Server Proxy added, the header is:
{
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"access_token": "foo",
"cache-control": "no-cache",
"connection": "keep-alive",
"content-length": "0",
"content-type": "application/json",
"host": "localhost:8081",
"login": "11111111111",
"postman-token": "72260d7c-6bd8-449a-95a7-290bf44bc61d",
"senha": "1234",
"user-agent": "PostmanRuntime/7.3.0"
}
But when I send request using Ionic Http request the header is:
{
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"accept-encoding": "gzip, deflate",
"accept-language": "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",
"access-control-request-headers": "access_token,content-type,login,senha",
"access-control-request-method": "POST",
"cache-control": "no-cache",
"connection": "keep-alive",
"host": "localhost:8081",
"origin": "http://localhost:8100",
"pragma": "no-cache",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0"
}
Why the very differences? My server it's work with first header.
Anybody helper me?
PHP REQUEST
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost:8081/api/card/login/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/json",
"access_token: foo",
"login: 11111111111",
"senha: 1234"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
IONIC REQUEST
var headers = new Headers({
'Content-Type': 'application/json',
'senha': '1234',
'login': '11111111111',
'access_token': 'foo'
})
let options = new RequestOptions({
headers: headers,
method: RequestMethod.Post,
withCredentials: true
})
this.httpClient.post("http://localhost:8081/api/card/login/", {}, options).subscribe(data => {
console.log(data['_body'])
}, error => {
console.error('API Error : ', error.status)
console.error('API Error : ', JSON.stringify(error))
})