Receiving a string value from client to server - php

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.

Related

Empty $request->request and $request->files with multipart/form-data

I am trying to upload a form with a file to my server using AJAX, but Symfony doesn't parse the request body like it should. This is my PHP:
#[Route('/api/upload/file', name: "api_upload_file", methods: ['POST'])]
public function create(Request $request): JsonResponse
{
dump($request->files->all());
dump($request->request->all());
dump($request->getContent());
...
and the dump output (The file part is cut out because it takes a lot of space) :
[]
[]
"""
------WebKitFormBoundaryh4t0I09h9iTRNGme
Content-Disposition: form-data; name="subcategory"
1
------WebKitFormBoundaryh4t0I09h9iTRNGme
Content-Disposition: form-data; name="main_image"; filename=""
Content-Type: application/octet-stream
------WebKitFormBoundaryh4t0I09h9iTRNGme
Content-Disposition: form-data; name="more_images"; filename=""
Content-Type: application/octet-stream
------WebKitFormBoundaryh4t0I09h9iTRNGme
Content-Disposition: form-data; name="original_version"
------WebKitFormBoundaryh4t0I09h9iTRNGme
Content-Disposition: form-data; name="version"
------WebKitFormBoundaryh4t0I09h9iTRNGme
Content-Disposition: form-data; name="original_title"
------WebKitFormBoundaryh4t0I09h9iTRNGme
Content-Disposition: form-data; name="title"
"""
The request clearly gets through so I do not understand why the content is not parsed
Just in case, here is the javascript part : (This looks like JQuery but is not)
form.submit(e => {
e.preventDefault();
let formData = createItemForm.formData();
$.ajax('/api/upload/file', {
headers: {
'Content-Type': 'multipart/form-data'
},
body: formData
})
.then(data => data.json())
.then(json => {
console.log('uploaded');
});
});
How should I do to get the files and the form values in $request->files and $request->request ?
DO NOT specify the Content-Type header yourself, when trying to make such a multipart request. That header needs to include the boundary value (so that the receiver will know how to parse this request) - if you specify it yourself, as just multipart/form-data, then that will be missing.
These request libraries usually know how to properly set it on their own, based on that you are passing in a FormData instance.

Flutter http Post - StatusCode 401 - repetition of response

I have some trouble with my Http Post Request in Flutter. I must connect to a PHP web service (using a header) and post some user/password info to get a response (here, user info).
I believe I am near to the solution but I still get a StatusCode 401 as response despite the fact that it works when I try with Postman (with same credentials).
Here is the code of the function I call :
Future<http.Response> post() async {
var url = "https://www.monadresse/login.php";
String password = "xxx";
String username = "yyy";
//var bytes = utf8.encode("$username:$password");
var bytes = "$username:$password";
String userNameUser = "www";
String passwordUser = "zzz";
var passwordUserEncoded = base64.encode(utf8.encode(passwordUser));
//var passwordUserEncoded = base64.encode(passwordUser);
var headers = {
"Authorization": "Basic $bytes",
"Content-Type": "application/json",
};
var requestBody = json.encode({ 'user': userNameUser, 'password': passwordUserEncoded});
print(headers);
print(requestBody);
final http.Response response = await http.post(
url,
body: requestBody,
headers: headers,
);
if(response.statusCode == 200){
var responseJson = json.decode(response.body);
print(Utf8Codec().decode(response.bodyBytes));
print("Body: " + responseJson);}
print(bytes);
print(passwordUserEncoded);
print(response.statusCode);
print("Fini");
}
Another weird thing (read 'I don't understand')... I have added some prints to have an idea of what's happening and, as you can see hereunder, the 2 first prints (located before the request) are first printed twice and after that the 3 last prints are also repeated twice.
flutter: {Authorization: Basic yyy:xxx, Content-Type: application/json}
flutter: {"user":"www","password":"zzz"}
flutter: {Authorization: yyy:xxx, Content-Type: application/json}
flutter: {"user":"www","password":"zzz}
flutter: yyy:xxx
flutter: zzz
flutter: 401
flutter: Fini
flutter: yyy:xxx
flutter: zzz
flutter: 401
flutter: Fini
As I don't find a solution on the net I very hope someone will help me.
As mentioned in the comments, the cause of this issue is that the 'username:password' used in the authorization header isn't encoded to base64.
Here's a working sample for basic authentication using test endpoints from Postman. The username is postman and the password is password.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert' show utf8, base64;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var _usernameTextController = TextEditingController();
var _passwordTextController = TextEditingController();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextFormField(
controller: _usernameTextController,
decoration: const InputDecoration(
labelText: 'Username',
),
),
TextFormField(
controller: _passwordTextController,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password',
),
),
ElevatedButton(
child: Text('Login'),
onPressed: _doLogin(_usernameTextController.text, _passwordTextController.text),
)
],
),
),
),
);
}
_doLogin(String username, String password) {
if (username.trim().isEmpty || password.trim().isEmpty) {
debugPrint('Either username or password is empty');
} else {
_login(username, password)
.then((value) => debugPrint('Login finished $value'))
.catchError((error) => debugPrint('Login error: $error'));
}
}
Future _login(String username, String password) async {
// 'username:password' is base64 encoded
var authHeader = '${base64.encode(utf8.encode('$username:$password'))}';
debugPrint('userpass: ${username + password}');
debugPrint('authHeader: $authHeader');
final response = await http.get(
'https://postman-echo.com/basic-auth',
headers: {HttpHeaders.authorizationHeader: "Basic $authHeader"},
);
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
return response.body;
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
throw Exception(
'Failed to login [${response.statusCode}] ${response.body}');
}
}
}

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

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.

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

Setup sending post request from android to php script

Android Retrofit's servise interface:
//#Headers("Authorization: " + BuildConfig.CLIENT_NAME + " " + BuildConfig.CLIENT_PASSWORD)
#FormUrlEncoded
#POST("api/post/report")
Observable<Object> postReport(#Field("message") String message);
Android monitor tells:
--> POST http://<mysite>/api/post/report http/1.1
D/OkHttp: Content-Type: application/x-www-form-urlencoded
D/OkHttp: Content-Length: 104
D/OkHttp: message=%D0%B2%D0%BB%D0%BE%D1%81%D0%B8%3A%20%D1%81%D0%BB%D1%87%D0%BB%D1%8C%D1%8F%D0%B1%D1%8B%D0%B6%D1%8B
D/OkHttp: --> END POST (104-byte body)
I do not know how to catch the Message from PHP.
$_POST - is empty
parse_str(file_get_contents("php://input"), $data);
$data = (object)$data;
Different variants of ^ are also not working. They returns nullable results, empty objects and ext
You are making a POST request.
print_r($_POST);
Should give you the value sent from retrofit.
Ok.ok. I did this:
//#Headers("Authorization: " + BuildConfig.CLIENT_NAME + " " + BuildConfig.CLIENT_PASSWORD)
#POST("api/post/report")
Observable<Object> postReport(#Header("message") String message);
I sent this via Header & catched the message with getHeaders() method...

Categories