I'm getting a 401 when trying to access the laravel api from vuejs using axios.
It's the Laravel 5.4 out-of-the-box setup so I have no idea why it doesn't work.
Here is my code:
// routes -> api.php
Route::middleware('auth:api')->get('/user', function (Request $request) {
return request->user();
});
// axios request
axios.get('/api/user').then(function (response) {
console.log(response);
console.log(response.status);
});
Request contains all the token stuff.. I think.
X-CSRF-TOKEN:uAW2t..
X-Requested-With:XMLHttpRequest
X-XSRF-TOKEN:eyJpdiI..
All response by request:
General
Request URL:http://localhost/public/api/user
Request Method:GET
Status Code:401 Unauthorized
Remote Address:[::1]:80
Response Headers
view source
Cache-Control:no-cache, private
Connection:Keep-Alive
Content-Length:28
Content-Type:application/json
Date:Wed, 22 Mar 2017 09:35:49 GMT
Keep-Alive:timeout=5, max=92
Server:Apache/2.4.23 (Win64) PHP/5.6.25
X-Powered-By:PHP/5.6.25
X-RateLimit-Limit:60
X-RateLimit-Remaining:57
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:XSRF-TOKEN=eyJpdiI6IjNBVHdDNWdsTnBYT3FUT1E5d1IxTmc9PSIsInZhbHVlIjoiY05JYW9LdDB3ek5FVjRWYkVEM21NQlFEQnNPdHI0Rk5MdWhKbFcrZU1qWFB5MGIyXC9oR1RQNGJkdTB6RmZ3SFp1OU04S0RpazYzZW5ZNUhVMng1VCtnPT0iLCJtYWMiOiIyZTQ5ZDdlYTgwYmMzZTYxYjMzMjljMmNlMDJlYWFlNTNkNzJkZmY5ZGVlMTQ5ZjlmZDM4NTYzOTc1MjIwYzhkIn0%3D; laravel_session=eyJpdiI6IkhcLzJKRDVDTHRDN1FWUjZicDdZaVJnPT0iLCJ2YWx1ZSI6IlJoTkVQWUQ5OWZuYUo4bmF1eHRMYWFlamZramhtTkpmMnYwbUlaaTV3ZENuWFJQZW9IcDZxbU5EQjJXSDY2a01WMHpjeHU3Uk9UOG44MzN3NmgxK2NBPT0iLCJtYWMiOiI4OWM1ZWI3YjIzMDg5MTAwYjc0YmZmZDE4OTY3MjU5OTNkZDdjYjY2MjU3NmFlNTE3NDE2NTVjYzBhY2Y4MzJmIn0%3D
DNT:1
Host:localhost
Referer:http://localhost/public/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
X-CSRF-TOKEN:uAW2tI8bags0CaQaYBKmbfdExoCVDnZlJb1sW9f4
X-Requested-With:XMLHttpRequest
X-XSRF-TOKEN:eyJpdiI6IjNBVHdDNWdsTnBYT3FUT1E5d1IxTmc9PSIsInZhbHVlIjoiY05JYW9LdDB3ek5FVjRWYkVEM21NQlFEQnNPdHI0Rk5MdWhKbFcrZU1qWFB5MGIyXC9oR1RQNGJkdTB6RmZ3SFp1OU04S0RpazYzZW5ZNUhVMng1VCtnPT0iLCJtYWMiOiIyZTQ5ZDdlYTgwYmMzZTYxYjMzMjljMmNlMDJlYWFlNTNkNzJkZmY5ZGVlMTQ5ZjlmZDM4NTYzOTc1MjIwYzhkIn0=
If you authorising user to use api you have to have a token either in url or in authorisation header key. That token should be from api_token column in users table.
var token = 'exampleToken';
axios.get(
'/api/user?api_token=' + token, // here
{
headers:
{
'Authorization':'Bearer ' + token // or here
}
}
).then(...)
axios.get('/api/user',{headers:{
'Accept':'application/json',
'Authorization':'Bearer ' + window.localStorage.getItem('token_name_here')
'cache-control':'no-cache'
}).then(...)...
Related
I have a situation like this.A SOAP request is sent from an application to our server.
The request works fine when testing locally but always fails when testing live on the dev server.
The administrator of that application sent me their request so I can test it and figure out what is wrong. So when I remove the Transfer-encoding: chunked header the response is fine (from Postman and SoapUI) but with the Transfer-encoding header present it fails.
Here is the request that is sent to our web service:
request headers:
POST http://xxx.dev.xxx.si/soap-mobile HTTP/1.1
Content-Type: text/xml; charset=UTF-8
Accept: */*
SOAPAction:"http://wtb.si/storitve/app/onlineGorillaMobile/v1/ZapisiVprasanjaZaUporabnika"
User-Agent: Apache CXF 2.4.6
Cache-Control: no-cache
Pragma: no-cache
Host: xxx.dev.xxx.si
Connection: keep-alive
Transfer-Encoding: chunked
request body:
ff9
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns8:ZapisiVprasanjaZaUporabnika xmlns:ns2="http://wtb.si/sheme/ponudbe/ipo/bean/v1" xmlns:ns3="http://wtb.si/sheme/ponudbe/ipo/v1" xmlns:ns4="http://wtb.si/sheme/ponudbe/v1" xmlns:ns5="http://wtb.si/sheme/skupno/v1" xmlns:ns6="http://wtb.si/sheme/app/onlineGorilla/sporocila/v1" xmlns:ns7="http://wtb.si/sheme/podpora/v1" xmlns:ns8="http://wtb.si/storitve/app/onlineGorillaMobile/v1" xmlns:ns9="http://wtb.si/sheme/zavarovanja/skupno/v1" xmlns:ns10="http://wtb.si/sheme/zavarovanja/bean/v1" xmlns:ns11="http://wtb.si/sheme/ponudbe/skupno/v1"><input><ns6:vprasanjaZaUporabnika><ns10:vprasanjaZaVrstoPredmetaZavarovanja><ns10:vrstaPredmetaZavarovanja>avto</ns10:vrstaPredmetaZavarovanja><ns10:vprasanja><ns4:parameterPaketa><ns4:iidParPaket>25390</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ŠTEVILKE</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>Stanje števca (km)</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>STEVILO_JS</ns11:tip><ns4:iidParameter>448101</ns4:iidParameter><ns4:parameter>P244</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25392</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>false</ns11:prostiVnos><ns11:naziv>Lastnik vozila</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>SEZNAM</ns11:tip><ns4:iidParameter>448103</ns4:iidParameter><ns4:parameter>P246</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:parameterLOVsDTO><ns4:parameterLOV><ns4:iidLov>498562</ns4:iidLov><ns4:iidParameter>448103</ns4:iidParameter><ns4:vrednost>1</ns4:vrednost><ns4:vrstniRed>1</ns4:vrstniRed><ns4:prikazanaVrednost>fizièna oseba</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV><ns4:parameterLOV><ns4:iidLov>498563</ns4:iidLov><ns4:iidParameter>448103</ns4:iidParameter><ns4:vrednost>2</ns4:vrednost><ns4:vrstniRed>2</ns4:vrstniRed><ns4:prikazanaVrednost>podjetje</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV><ns4:parameterLOV><ns4:iidLov>498564</ns4:iidLov><ns4:iidParameter>448103</ns4:iidParameter><ns4:vrednost>3</ns4:vrednost><ns4:vrstniRed>3</ns4:vrstniRed><ns4:prikazanaVrednost>lizing</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV></ns4:parameterLOVsDTO><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25393</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>false</ns11:prostiVnos><ns11:naziv>Mladi voznik</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>CK</ns11:tip><ns4:iidParameter>448104</ns4:iidParameter><ns4:parameter>P247</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:parameterLOVsDTO><ns4:parameterLOV><ns4:iidLov>498565</ns4:iidLov><ns4:iidParameter>448104</ns4:iidParameter><ns4:vrednost>1</ns4:vrednost><ns4:vrstniRed>1</ns4:vrstniRed><ns4:prikazanaVrednost>da</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV><ns4:parameterLOV><ns4:iidLov>498566</ns4:iidLov><ns4:iidParameter>448104</ns4:iidParameter><ns4:vrednost>2</ns4:vrednost><ns4:vrstniRed>2</ns4:vrstniRed><ns4:prikazanaVrednost>ne</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV></ns4:parameterLOVsDTO><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25394</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ŠTEVILKE</ns11:vrsta><ns11:prostiVnos>false</ns11:prostiVnos><ns11:naziv>Starost voznika</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>SEZNAM</ns11:tip><ns4:iidParameter>448105</ns4:iidParameter><ns4:parameter>P248</ns4:parameter><ns4:casS
ff9
ekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25395</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>DATUM</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>Datum pridobitve voznikega dovoljenja</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>DATUM_GUMB</ns11:tip><ns4:iidParameter>448106</ns4:iidParameter><ns4:parameter>P249</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25431</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>false</ns11:prostiVnos><ns11:naziv>Število prevoženih km na leto</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>SEZNAM</ns11:tip><ns4:iidParameter>448126</ns4:iidParameter><ns4:parameter>P269</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:parameterLOVsDTO><ns4:parameterLOV><ns4:iidLov>498560</ns4:iidLov><ns4:iidParameter>448126</ns4:iidParameter><ns4:vrednost>1</ns4:vrednost><ns4:vrstniRed>1</ns4:vrstniRed><ns4:prikazanaVrednost>manj kot 10.000 km</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV><ns4:parameterLOV><ns4:iidLov>498561</ns4:iidLov><ns4:iidParameter>448126</ns4:iidParameter><ns4:vrednost>2</ns4:vrednost><ns4:vrstniRed>2</ns4:vrstniRed><ns4:prikazanaVrednost>med 10.000 in 20.000 km</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV><ns4:parameterLOV><ns4:iidLov>498569</ns4:iidLov><ns4:iidParameter>448126</ns4:iidParameter><ns4:vrednost>3</ns4:vrednost><ns4:vrstniRed>3</ns4:vrstniRed><ns4:prikazanaVrednost>med 20.000 in 30.000 km</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV><ns4:parameterLOV><ns4:iidLov>498570</ns4:iidLov><ns4:iidParameter>448126</ns4:iidParameter><ns4:vrednost>4</ns4:vrednost><ns4:vrstniRed>4</ns4:vrstniRed><ns4:prikazanaVrednost>med 30.000 in 40.000 km</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV><ns4:parameterLOV><ns4:iidLov>498571</ns4:iidLov><ns4:iidParameter>448126</ns4:iidParameter><ns4:vrednost>5</ns4:vrednost><ns4:vrstniRed>5</ns4:vrstniRed><ns4:prikazanaVrednost>veè kot 40.000 km</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV></ns4:parameterLOVsDTO><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25432</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>false</ns11:prostiVnos><ns11:naziv>Ali imate garažo</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>SEZNAM</ns11:tip><ns4:iidParameter>448127</ns4:iidParameter><ns4:parameter>P270</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:parameterLOVsDTO><ns4:parameterLOV><ns4:iidLov>498572</ns4:iidLov><ns4:iidParameter>448127</ns4:iidParameter><ns4:vrednost>1</ns4:vrednost><ns4:vrstniRed>1</ns4:vrstniRed><ns4:prikazanaVrednost>da</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV><ns4:parameterLOV><ns4:iidLov>498573</ns4:iidLov><ns4:iidParameter>448127</ns4:iidParameter><ns4:vrednost>2</ns4:vrednost><ns4:vrstniRed>2</ns4:vrstniRed><ns4:prikazanaVrednost>ne</ns4:prikazanaVrednost><ns4:jezik>sl</ns4:jezik></ns4:parameterLOV></ns4:parameterLOVsDTO><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25433</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>Ste veliko na poti</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>LOV_GUMB</ns11:tip><ns4:iidParameter>448128</ns4:iidParameter><ns4:parameter>P271</ns4:parameter><ns4:casSekvenca>
dbb
false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25434</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>Ali potujete v tujino</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>LOV_GUMB</ns11:tip><ns4:iidParameter>448129</ns4:iidParameter><ns4:parameter>P272</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25435</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>Službene poti</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>LOV_GUMB</ns11:tip><ns4:iidParameter>448130</ns4:iidParameter><ns4:parameter>P273</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25436</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>Vozite 220 na uro</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>LOV_GUMB</ns11:tip><ns4:iidParameter>448131</ns4:iidParameter><ns4:parameter>P274</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25437</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>Ste vedno prvi</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>LOV_GUMB</ns11:tip><ns4:iidParameter>448132</ns4:iidParameter><ns4:parameter>P275</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25438</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>ZNAKI</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>To je to</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>LOV_GUMB</ns11:tip><ns4:iidParameter>448133</ns4:iidParameter><ns4:parameter>P276</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa><ns4:parameterPaketa><ns4:iidParPaket>25439</ns4:iidParPaket><ns4:iidPaket>441218</ns4:iidPaket><ns4:parameter><ns11:vrsta>DATOTEKA</ns11:vrsta><ns11:prostiVnos>true</ns11:prostiVnos><ns11:naziv>Kopija obstojeèe police</ns11:naziv><ns11:jezik>sl</ns11:jezik><ns11:tip>DATOTEKA</ns11:tip><ns4:iidParameter>448134</ns4:iidParameter><ns4:parameter>P277</ns4:parameter><ns4:casSekvenca>false</ns4:casSekvenca><ns4:ipo>true</ns4:ipo><ns4:kolicina>false</ns4:kolicina></ns4:parameter><ns4:zahtevanVnos>false</ns4:zahtevanVnos></ns4:parameterPaketa></ns10:vprasanja></ns10:vprasanjaZaVrstoPredmetaZavarovanja></ns6:vprasanjaZaUporabnika></input></ns8:ZapisiVprasanjaZaUporabnika></soap:Body></soap:Envelope>
0
response headers + response body:
HTTP/1.1 400
status: 400
date: Mon, 24 Sep 2018 09:00:59 GMT
server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips mod_fcgid/2.3.9 PHP/5.4.16 mod_python/3.5.0- Python/2.7.5
connection: close
content-type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>400 Bad Request</title> </head><body> <h1>Bad Request</h1> <p>Your browser sent a request that this server could not understand.<br /> </p> <p>Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.</p> </body></html> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>503 Service Unavailable</title> </head><body> <h1>Service Unavailable</h1> <p>The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.</p> <p>Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.</p> </body></html>
I suspect that something goes wrong during the request when it sends the chunks of data in several requests on the same connection. Not really sure because i'm doing this for the first time.
I am using Laravel 5.6.38. Below is the code called from the application:
public function handle(Request $request) {
$opts = array(
'http' => array(
'Content-Type' => 'text/xml; charset=utf-8',
'User-Agent' => 'PHP/SOAP',
'Allow' => 'GET,POST',
'Accept-Encoding:' => 'gzip, deflate, br',
));`
$context = stream_context_create($opts);
$soapOptions = array(
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE,
'encoding' => 'UTF-8',
//'uri' => public_path().'/soap/storitve/app/onlineGorillaMobile/v1/OnlineGorillaMobile.wsdl'
);
try {
$server = new \SoapServer(public_path().'/soap/storitve/app/onlineGorillaMobile/v1/OnlineGorillaMobile.wsdl', $soapOptions);
//$server = new \SoapServer(null, $soapOptions);
}
catch (\SoapFault $sf) {
Log::channel('soap')->info("SOAPfault: ".$sf->faultstring." (".$sf->faultcode.")");
}
$server->setObject(new Soap());
ob_start();
$server->handle();
$response = ob_get_clean();
return response($response)->header('Content-Type', 'text/xml; charset=UTF-8')->header('Host', env('HEADER_HOST'))->header('Allow', 'GET,POST');
}
Here is some log data that is made on each request:
ob_get_status(true)
0 =>
array (
'name' => 'default output handler',
'type' => 0,
'flags' => 112,
'level' => 0,
'chunk_size' => 4096,
'buffer_size' => 8192,
'buffer_used' => 0,
),
)
headers_list()
array (
0 => 'X-Powered-By: PHP/7.2.3',
1 => 'Content-Type: text/xml; charset=utf-8',
)
$this->_client->__getLastRequestHeaders()
POST /ponudbe-storitve-3.0.0/OnlineGorilla/OnlineGorilla HTTP/1.1
Host: xxxx-nabava.xxxxxxxx.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/7.2.3
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://wtb.si/storitve/app/onlineGorilla/v1/VpisiProfilUporabnikaInPolice"
Content-Length: 263972
Postman Screenshot:
Sorry for the extensive post but I am having a battle with this problem for a week now and I am getting desperate so any help will be appreciated.
edit:
some additional info:
When in Postman sending the request with the Transfer-Encoding: chunked header present the logging stops at the same moment when the
$server = new SoapServer('....... line is called
[2018-09-24 14:27:57] local.INFO: initiating SoapServer
[2018-09-24 14:27:57] local.INFO: array (
)
[2018-09-24 14:28:02] local.DEBUG: array (
)
without the Transfer-Encoding the logging continues as it should. So the whole request stops at that point.
best regards
I got the idea for the solution in the question below:
Querying Exchange Web Service gives Bad Request (400) with WildFly and Apache CXF
The application that calls our Soap service is on Java Apache CXF, so all we had to do was disable chunking on their side and that did it.
I'm implementing a JWT authentification and I got a problem with the authorization set in the header.
It's looking like the 'Authorization' header isn't set in the request.
I got 2 request send by the client, the first one, the Authorization header pass in the request :
// GET PROJECTS NAME
projects.getName = () => { // === projects.getName = function() { ... }
return $http.get(Global.url_api+'action=GETINFO&table=Projects');
}
Request in browser :
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOi....
Host: *******-tpinst.fr
Origin: http://localhost:2000
Proxy-Connection: keep-alive
Referer: http://localhost:2000/
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
But my second request implemented as the same as the first one didn't pass this authorization header :
users.get = function(project){
return $http.get(Global.url_api+'action=GET&table='+project+'_users');
}
In the browser :
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
Access-Control-Request-Headers: authorization
Access-Control-Request-Method: GET
Host: bouygues-tpinst.fr
Origin: http://localhost:2000
Proxy-Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
The authorization is set in main program :
app.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.common['Authorization'] = 'Bearer
'+localStorage.getItem('tokenAPI');
}])
I set Allow origin in my server side with these lines :
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE,
OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, Authorization');
I'm a beginner in these security notions, please guide me on a good way
EDIT :
I just found a hint, in my api.php i got this line to send error 401 to client :
$Authorization = $_SERVER['HTTP_AUTHORIZATION'];
//Looking for authorization headers
if($Authorization){ ... }
else {
header('HTTP/1.0 401 Unauthorized'); //Give error code 401
echo 'Token not found in the header';
}
When i delete
header('HTTP/1.0 401 Unauthorized');
The Authorization pass in the header
Remove the $httpProvider.defaults.headers.common
instead implement an http interceptor
Try this
app.factory("authInterceptor", authInterceptor);
authInterceptor.$inject = ["$q"];
function authInterceptor($q) {
return {
// Add an interceptor for requests.
'request': function (config) {
// Default to an empty object if no headers are set.
config.headers = config.headers || {};
// Set the token
var token = localStorage.getItem('tokenAPI');
config.headers.Authorization = "Bearer " + token;
return config;
},
// Add an interceptor for any responses that error.
'responseError': function (response) {
// Check if the error is auth-related.
if (response.status === 401 || response.status === 403) {
}
return $q.reject(response);
}
};
}
app.config(["$httpProvider",
function ($httpProvider) {
//Registers the interceptor
$httpProvider.interceptors.push("authInterceptor");
}]);
And i think the re-arrangement of your scripts causes the issue, place your controller script in the bottom
something like this
And in your main.js remove the
var app = angular.module('App', ['ngMaterial', 'ngMessages']) because we placed it in the index.html
What is the equavalent of php getallheaders() function in Angular 4/5 ?
I need to get request headers but i can't find this in Angular. I can get only response headers with Angular.
I need to get request header parameters when application start not sending get or post request. In picture i need X-MSISDN and X-IMSI parameters
I try Interceptor class but its only works when i send get or post requests.
Explanation:
I open application with this url : http://localhost:4200/#/
In this time my request header is like this:
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Cookie: s_fid=07C355F600B90B3D-291EBB86E5858A2F; s_cc=true; gdslv_s=Less%20than%201%20day; s_vnum=1556196774798%26vn%3D7; s_invisit=true; s_ppvl=login%2520sayfasi%2C100%2C100%2C933%2C375%2C667%2C375%2C667%2C2%2CLP; s_ppv=Welcome%253Atarife%253Aanasayfa%2C100%2C100%2C667%2C375%2C667%2C375%2C667%2C2%2CP; s_ppn=Welcome%3Atarife%3Aanasayfa; gdslv=1524831169979; s_getNewRepeat=1524831169981-Repeat; utag_main=v_id:0162fcdd2735001117d070e941e904072002406a00918$_sn:7$_ss:0$_st:1524832969982$_pn:2%3Bexp-session$ses_id:1524831079859%3Bexp-session$_prevpage:Welcome%3Atarife%3Aanasayfa%3Bexp-1524834769972
Host: localhost:4200
Pragma: no-cache
Referer: http://localhost:4200/
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1
X-IMSI: 286026134103281
X-MSISDN: 905499914581
Request URL : http://localhost:4200/sockjs-node/info?t=1524831359435
I need to take X-IMSI and X-MSISDN parameters.
Following my comment : you could create a service that is in charge of handling all of your headers. That's also a good practice : you centralize the logic of a feature.
Here is an instance of a service that can do that. It can create JSON headers, append new headers to the list, reset them ... See for yourself.
import { Injectable } from '#angular/core';
import { Headers } from '#angular/http';
#Injectable()
export class HeadersManagerService {
private headers: Headers;
constructor() {
this.resetHeaders();
}
resetHeaders() {
this.headers = new Headers();
}
newHeader(key, value) {
this.headers.append(key, value);
}
createJsonHeaders() {
this.resetHeaders();
this.headers.append('Content-Type', 'application/json');
}
getHeaders() {
return this.headers;
}
}
PS: Posting as an answer because it's too long for a comment.
Why don't you try like this
setHeaders() {
const headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded'
});
const options = new RequestOptions({ headers: headers });
console.log(options.headers);
// return options;
}
In angular if it is object, for example
obj{name:"ABC" , role:"Student"} then Object.keys(obj); will return headers
i played around with Laravel 5 and i just tried to send POST to my controller.
all seems to work but the success ajax method is not called. Instead the complete method is triggered. the header status is 200 and no error occurs.
Here is my load function:
load: function() {
$.ajax({
cache: false,
url: 'index.php/profile/sayings',
type: "post",
dataType: 'JSON',
data: {'_token': $('meta[name=_token]').attr('content')},
success: function(data) {
console.log(data);
},
complete: function(data) {
console.log(data);
}
});
Routing:
Route::post('profile/sayings', 'ProfileController#sayings');
Controller:
public function sayings() {
return Response::json($this->docHelper->getSayings(), 200);
}
request header:
POST /profile_dyn/laravel/index.php/profile/sayings HTTP/1.1
Host: 192.168.1.104
Connection: keep-alive
Content-Length: 47
Cache-Control: max-age=0
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://192.168.1.104
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://192.168.1.104/profile_dyn/laravel/
Accept-Encoding: gzip, deflate
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: XSRF-TOKEN=eyJpdiI6IjNBQUVHeFZcL0RaY21vNWQ0RHdiQ3RBPT0iLCJ2YWx1ZSI6IkY1MHR2K2ZLdnQxMzFkK2cxSFwvQ1pqZEVFYnNBaWdvZ05WQTJuSmF6ZU9jQ295WGpRSnFpaTZVZnMwYit0XC8xMGtWYm1leTQ2SGw3QXlzMUJxdWxcL01BPT0iLCJtYWMiOiJkYTVkMjUzMzJjNGRhMGIwNTY0YzJlY2FjNjhhMzFmNDQ5ZWQ3MGNkMTY0ZDNjZDM1OWQ5MzBkMWY4YTYzZjU5In0%3D; laravel_session=eyJpdiI6InZQdk40M05mbXpWQXFVdENuK3l5bHc9PSIsInZhbHVlIjoiM0ZiYWhoN1Fmd3FjZWlCcU1yT1JYbjVNZkJDbmtPbFgxa2ZyRENBd2ptYzhMdU01UVBSdHRjUUtjMzE4M1VcL0h6aEtoYkFxTzdHb0pCbTJWdHhpZWt3PT0iLCJtYWMiOiIyZmVjZTY2NzFhNDZiNWRjYTQ2MWMwYTg4NjM1YzQ1YjQ0YWZjZDA0MmQ2Nzc1MGU4ZTk0MjVkZjA2NjZjNDljIn0%3D
X-FirePHP: 0.4.4
X-FirePHP-Version: 0.4.4
X-Wf-Max-Combined-Size: 262144
response header:
HTTP/1.1 200 OK
Date: Sat, 19 Sep 2015 19:58:01 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.11
Cache-Control: no-cache
Set-Cookie: XSRF-TOKEN=eyJpdiI6IjhsdjVxbUtcL1RTR2p0N1JjeE5UTXd3PT0iLCJ2YWx1ZSI6Imt6TDdKd1M5UFwvUVlraTNXZDQrUkJXOFNCWjNpdURCR0gwMkRza3NIazZSM2pQVUxoMzlmd2EzRDB2cUMrVU51ajFibUduaVMzcEt3OFNKSnN6Ukhsdz09IiwibWFjIjoiOTY4YWUwMWZiMjU4YWI2OGExNmY2NTAwMzc0N2RmMzNiNDY4YWVlZDU3NDQzMmM5ZjI1MmU3ZTA0NTlkNDU2YyJ9; expires=Sat, 19-Sep-2015 21:58:01 GMT; Max-Age=7200; path=/
Set-Cookie: laravel_session=eyJpdiI6InVQQkNlM0FDMGYyNVliS1pvZUQ4RkE9PSIsInZhbHVlIjoiS3ZjbmRrNFRzQjRCRXNLQnFvVHBicHhhVGQ4cjRKR0pcL085aXJKc3A5bmZZZmh1SFNmQTRZeVZxUktYdVhUcDVwaGRHOG1SR0N2RTBUd1ZtSUlXSnh3PT0iLCJtYWMiOiIzOTkyZTRkOWJlZjllZWFkN2I3YjM4M2EzZWNjZWE3YjEwNzYzNGExYjEwNzdlYmMyODNlMmFhODU1ODkwYTI5In0%3D; expires=Sat, 19-Sep-2015 21:58:01 GMT; Max-Age=7200; path=/; httponly
Content-Length: 3906
Keep-Alive: timeout=5, max=94
Connection: Keep-Alive
Content-Type: application/json
Just the complete function fires with status 200, statusText ok, readyState 4 and a valid responseText.
If the http header is not 200, complete would be fine. I do not know any reason for not firing success in this case. Probably one of you could explain this behaviour.
Cheers
The next problem is try to consume a web service. I try with plugins and pure xml but the result still be "NULL".
The code is this.
function soap(imei,clave)
{
var divToBeWorkedOn = "#res";
var webServiceURL = '';
var parameters = '<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd=" http://www.w3.org/2001/XMLSchema " xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<registra_imei> \
<request> \
<imei>'+imei+'</imei> \
<clave>'+clave+'</clave> \
</request> \
</registra_imei> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
type: "Post",
url: webServiceURL,
data: parameters,
contentType: "text/xml; charset=\"utf-8\"",
dataType: "xml",
success: function(msg) {
alert("funciono "+msg);
},
error: function(e){
alert("error");
}
});
}
The Web services is a simple SOAP PHP. Just I need send the variables and then get a response that will be a code (1, 2 or 3).
The requeriment from the event "registra_imei" are this:
Name: registra_imei
Binding: SOAPBinding
Endpoint:
SoapAction: urn:soapwsdl#registra_imei
Style: rpc
Input:
use: encoded
namespace: urn:soapwsdl
encodingStyle: http://schemas.xmlsoap.org/soap/encoding/
message: registra_imeiRequest
parts:
imei: xsd:string
clave: xsd:string
Output:
use: encoded
namespace: urn:soapwsdl
encodingStyle: http://schemas.xmlsoap.org/soap/encoding/
message: registra_imeiResponse
parts:
return: xsd:int
Namespace: urn:soapwsdl
Transport: http://schemas.xmlsoap.org/soap/http
Documentation: Registra imei
My comment is too long to post it into the comment area.
So, using SoapUI i simulated a call to your WSDL and i got this as a RAW response:
HTTP/1.1 200 OK
Date: Tue, 14 Apr 2015 19:44:24 GMT
Server: LiteSpeed
X-Powered-By: PHP/5.4.39
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Set-Cookie: PHPSESSID=870fgce5tm1ep8get75066i491; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Content-Length: 0
This is the SOAP request:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:soapwsdl">
<soapenv:Header/>
<soapenv:Body>
<urn:registra_imei soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<imei xsi:type="xsd:string">65656565</imei>
<clave xsi:type="xsd:string">123</clave>
</urn:registra_imei>
</soapenv:Body>
</soapenv:Envelope>
RAW request:
POST http://soap.movilaccesscloud.cl/serversoap.php/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:soapwsdl#registra_imei"
Content-Length: 508
Host: soap.movilaccesscloud.cl
Proxy-Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Apparently, the error is in the back-end of your webservice. Check your PHP code, if possible please share part of the code.
I repeat, my intention was to put the comment in the proper area, but as you can see it´s too long.
:)