getting 400 bad request on SOAP requests (Transfer-encoding: chunked problem?) - php

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.

Related

What is the equavalent of php getallheaders() function in Angular 4/5?

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

Receiving a string value from client to server

I am working on Android along with yii-2 php. From my app I am sending some photos in a file using an api call. Along with it I am sending a reference number as shown below.
#Multipart
#POST("installation/photo/save")
Call<ApiResponse> uploadImage(#Header("Authorization") String token, #Part("ref_no") RequestBody ref_no, #Part MultipartBody.Part file);
The call is initialized as shown below
Retrofit retrofit = RetrofitClient.getClient();
RetrofitInterface retrofitInterface = retrofit.create(RetrofitInterface.class);
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("uploaded_file", file.getName(), requestFile);
RequestBody ref_no = createPartFromString("<ref_no>");
ref_no = createPartFromString(installationDetails.getReferenceNo());
Call<ApiResponse> call = retrofitInterface.uploadImage("Bearer " + Common.getAuthKey(mContext),ref_no, body);
call.enqueue(new Callback<ApiResponse>() {
#Override
public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) {
if (response.isSuccessful()) {
Log.d(TAG, response.body().getStatus());
if (response.body().getStatus().equals("OK")) {
snapManager.updateSnapStatus(AssetsManagementContract.SnapEntry.COLUMN_SITE_SNAP, snap.getSnapName(), Constants.SNAP_SYNCED);
Intent broadcastSyc = new Intent();
broadcastSyc.setAction(Common.GetSyncImageAction());
broadcastSyc.putExtra("STATUS", true);
mContext.sendBroadcast(broadcastSyc);
sendImage(mContext);
}
else{
snapManager.updateSnapStatus(AssetsManagementContract.SnapEntry.COLUMN_SITE_SNAP, snap.getSnapName(), Constants.SNAP_CLOSED);
}
} else {
snapManager.updateSnapStatus(AssetsManagementContract.SnapEntry.COLUMN_SITE_SNAP, snap.getSnapName(), Constants.SNAP_CLOSED);
Log.d(TAG, "Error");
}
}
Working of app
User note down the details of installation and take pictures
On closing the form two API's are called
i) API to save/upload installation data to server
ii) API to save/upload images to the server.
The images are uploaded when the Installation API response is returned OK.
OkHttp Log
When the images are pushed to the server below is the call in ok http
--> POST http://ip:port/api/web/v1/installation/photo/save
01-31 08:34:14.723 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Type: multipart/form-data; boundary=704cd1e5-e4d5-4d2e-be63-81f5fe3f1aef
01-31 08:34:14.723 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Length: 116027
01-31 08:34:14.724 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Authorization: Bearer key
01-31 08:34:14.745 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: --704cd1e5-e4d5-4d2e-be63-81f5fe3f1aef
01-31 08:34:14.747 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Disposition: form-data; name="ref_no"
01-31 08:34:14.748 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Transfer-Encoding: binary
01-31 08:34:14.748 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Type: multipart/form-data; charset=utf-8
01-31 08:34:14.754 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Length: 15
01-31 08:34:14.755 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: 28372250046142R //this is reference number
01-31 08:34:14.755 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: --704cd1e5-e4d5-4d2e-be63-81f5fe3f1aef
01-31 08:34:14.755 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Disposition: form-data; name="uploaded_file"; filename="28372250046142R_1517369623_site_1.jpg"
01-31 08:34:14.755 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Type: multipart/form-data
01-31 08:34:14.755 5762-6086/com.thumbsol.accuratemobileassetsmanagament D/OkHttp: Content-Length: 115567
Server Side
At server side below is API code through which images are saved.
public function actionSavephoto()
{
try {
$count = 0;
foreach ($_FILES as $f) {
$dd = pathinfo($f['name']);
if (!isset($dd['extension']) || !in_array($dd['extension'], array('jpg', 'png', 'gif'))) {
return ['status' => 'ERROR', 'uploaded_files' => $count, 'message' => 'Invalid File'];
break;
}
if (move_uploaded_file($f['tmp_name'], Installations::UPLOAD_FOLDER . $f['name'])) {
$count++;
return ['status' => 'OK', 'uploaded_files' => $count];
break;
} else {
return ['status' => 'ERROR', 'uploaded_files' => $count];
break;
}
}
} catch (Exception $x) {
return ['status' => 'ERROR', 'message' => $x->getMessage()];
}
}
The response after var_dump($dd) below is the response that generates.
array(4) {
["dirname"]=>
string(1) "."
["basename"]=>
string(37) "28372230019211U_1517370655_site_1.jpg"
["extension"]=>
string(3) "jpg"
["filename"]=>
string(33) "28372230019211U_1517370655_site_1"
}
In response there is no reference number. How can I get the reference number at server side?
Any help would be highly appreciated.
Check if there is $_POST['ref_no'] present at server side after the call.

Fails to send cookies on http request

I have vbscript code that send an ajax request to server with cookie using MSXML2.XMLHTTP object. I have read about this bug and workaround. By invoking setRequestHeader twice, cookies should properly sent..but that not happening..
The vbscript code:
Dim http
set http = WScript.CreateObject("MSXML2.XMLHTTP")
http.open "POST", "http://localhost/echo", false
http.setRequestHeader "X-Requested-With", "XMLHttpRequest"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "Cookie", "SESSID=f3rds19k7qu58pvmb80561dc76" '1st invoke '
http.setRequestHeader "Cookie", "SESSID=f3rds19k7qu58pvmb80561dc76" '2nd invoke '
http.send sReq
msgbox http.responseText
And on server side at http://localhost/echo/index.php contains code
<?php print_r(getallheaders());?>
that php code basically only echoing the request header back to the client, and even I invoke twice this what I got:
Array
(
[Accept] => */*
[X-Requested-With] => XMLHttpRequest
[Accept-Language] => id
[Accept-Encoding] => gzip, deflate
[User-Agent] => Mozilla/4.0 (bla..bla..bla...)
[Host] => localhost
[Connection] => Keep-Alive
[Cache-Control] => no-cache
)
As you can see no cookie on the header. How to make cookie sent properly to server?
Finally i found solution... simple.. just use WinHTTP.WinHTTPRequest instead of MSXML2.XMLHTTP
Dim http
set http = WScript.CreateObject("WinHTTP.WinHTTPRequest.5.1")
http.open "POST", "http://localhost/echo", false
http.setRequestHeader "X-Requested-With", "XMLHttpRequest"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "Cookie", "SESSID=f3rds19k7qu58pvmb80561dc76"
msgbox http.responseText

POST Response of Laravel 5 just triggers complete but not success

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

Phonegap Consuming Web Service PHP

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.
:)

Categories