I am trying to create a reset password page in ionic where the user enter his email ,to reset the password of his account on my application.
The thing is that I want to send a response from php telling the user if the email was sent to his email or not depending on values sent from php to ionic. The thing that is happening is that the email is sent but it is showing me a response error.
Here is my typescript code:
async sendEmail() {
var regEmail = /^([a-zA-Z0-9\.-_]+)#([a-zA-Z0-9-]+).([a-z]{2,20})$/;
if (!regEmail.test(this.resetPasswordForm.value.email)) {
this.showToast("Invalid email");
return;
}
const loading = await this.load.create({
message: 'Please wait...'
});
loading.present();
this.auth.sendEmailVerification(this.resetPasswordForm.value).subscribe((data) => {
console.log(data);
if (data == "sent") {
this.showAlert("Great!", "We have sent you an email, check your inbox.");
this.resetPasswordForm.reset();
}
else if (data == "notfound") {
this.showAlert("Error!", "This email was not found.");
} else if (data == "error") {
this.showAlert("Oupss!", "An error occured and email could not be sent.");
}
}, (err) => {
console.log(err);
this.showAlert("Error!", err.message);
});
loading.dismiss();
}
The php code:
<?php
session_start();
require("headers.php");
require("connection.php");
$userData=file_get_contents("php://input");
$request=json_decode($userData);
$to=$request->email;
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
require 'phpmailer/src/Exception.php';
$con=connect();
$checkUser="SELECT count(*) from users where email='$to'";
$res=mysqli_query($con,$checkUser);
$row=mysqli_fetch_array($res);
if($row[0]==1){
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
$randomNumber=mt_rand(100000,999999);
$_SESSION["random"]=$randomNumber;
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('no-reply#gmail.com','charbelalam755#gmail.com');
$mail->addAddress($to); // Add a recipient
print json_encode("sent");
// Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Password reset email for account: ".$to;
$mail->Body = "Your confirmation code to reset your password is: ".$randomNumber;
//$mail->AltBody =;
$mail->send();
} catch (Exception $e) {
print json_encode("error");
}
}else print json_encode("notfound");
mysqli_close($con);
?>
Here is the error that I am getting:
HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://127.0.0.1/interactive-contact-list/sendEmail.php", ok: false, …}
error:
error: SyntaxError: Unexpected number in JSON at position 6 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:8100/vendor.js:7290:51) at ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:3505:35) at Object.onInvokeTask (http://localhost:8100/vendor.js:64524:33) at ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:3504:40) at Zone.runTask (http://localhost:8100/polyfills.js:3273:51) at ZoneTask.invokeTask [as invoke] (http://localhost:8100/polyfills.js:3586:38) at invokeTask (http://localhost:8100/polyfills.js:4727:18) at XMLHttpRequest.globalZoneAwareCallback (http://localhost:8100/polyfills.js:4764:25)
message: "Unexpected number in JSON at position 6"
stack: "SyntaxError: Unexpected number in JSON at position 6↵ at JSON.parse (<anonymous>)↵ at XMLHttpRequest.onLoad (http://localhost:8100/vendor.js:7290:51)↵ at ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:3505:35)↵ at Object.onInvokeTask (http://localhost:8100/vendor.js:64524:33)↵ at ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:3504:40)↵ at Zone.runTask (http://localhost:8100/polyfills.js:3273:51)↵ at ZoneTask.invokeTask [as invoke] (http://localhost:8100/polyfills.js:3586:38)↵ at invokeTask (http://localhost:8100/polyfills.js:4727:18)↵ at XMLHttpRequest.globalZoneAwareCallback (http://localhost:8100/polyfills.js:4764:25)"
__proto__: Error
constructor: ƒ SyntaxError()
arguments: (...)
caller: (...)
length: 1
name: "SyntaxError"
prototype: Error {name: "SyntaxError", message: "", constructor: ƒ}
__proto__: ƒ Error()
[[Scopes]]: Scopes[0]
message: ""
name: "SyntaxError"
__proto__:
constructor: ƒ Error()
message: ""
name: "Error"
toString: ƒ toString()
__proto__: Object
text: ""sent"2020-12-27 13:33:10 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP s6sm56953899wro.79 - gsmtp<br>↵2020-12-27 13:33:10 CLIENT -> SERVER: EHLO 127.0.0.1<br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a00:6920:f0ef:dc7f:e42f:c0d7:fb12:ac22]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: STARTTLS<br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: EHLO 127.0.0.1<br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a00:6920:f0ef:dc7f:e42f:c0d7:fb12:ac22]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: AUTH LOGIN<br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 334 VXNlcm5hbWU6<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: [credentials hidden]<br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 334 UGFzc3dvcmQ6<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: [credentials hidden]<br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 235 2.7.0 Accepted<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: MAIL FROM:<no-reply#gmail.com><br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 250 2.1.0 OK s6sm56953899wro.79 - gsmtp<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: RCPT TO:<charbelalam756#gmail.com><br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 250 2.1.5 OK s6sm56953899wro.79 - gsmtp<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: DATA<br>↵2020-12-27 13:33:11 SERVER -> CLIENT: 354 Go ahead s6sm56953899wro.79 - gsmtp<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: Date: Sun, 27 Dec 2020 13:33:10 +0000<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: To: charbelalam756#gmail.com<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: From: "charbelalam755#gmail.com" <no-reply#gmail.com><br>↵2020-12-27 13:33:11 CLIENT -> SERVER: Subject: Password reset email for account: charbelalam756#gmail.com<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: Message-ID: <i0AwjHlt0fMW4cRQ1rpg8Qys7xyFLZyf2MKe365Y#127.0.0.1><br>↵2020-12-27 13:33:11 CLIENT -> SERVER: X-Mailer: PHPMailer 6.1.7 (https://github.com/PHPMailer/PHPMailer)<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: MIME-Version: 1.0<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: <br>↵2020-12-27 13:33:11 CLIENT -> SERVER: Your confirmation code to reset your password is: 805919<br>↵2020-12-27 13:33:11 CLIENT -> SERVER: <br>↵2020-12-27 13:33:11 CLIENT -> SERVER: .<br>↵2020-12-27 13:33:12 SERVER -> CLIENT: 250 2.0.0 OK 1609075990 s6sm56953899wro.79 - gsmtp<br>↵2020-12-27 13:33:12 CLIENT -> SERVER: QUIT<br>↵2020-12-27 13:33:12 SERVER -> CLIENT: 221 2.0.0 closing connection s6sm56953899wro.79 - gsmtp<br>↵"
__proto__:
constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ ()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()
headers: HttpHeaders
lazyInit: () => {…}
lazyUpdate: null
normalizedNames: Map(0) {}
__proto__: Object
message: "Http failure during parsing for http://127.0.0.1/interactive-contact-list/sendEmail.php"
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: "http://127.0.0.1/interactive-contact-list/sendEmail.php"
__proto__: HttpResponseBase
constructor: class HttpErrorResponse
__proto__: Object
I am using print json_encode("") to send response from php to ionic, it's working everywhere except this one.
Here's your problem:
$mail->SMTPDebug = 2;
PHPMailer's debug output is not JSON compatible, so turn it off:
$mail->SMTPDebug = 0;
You an of course turn it into JSON by injecting your own debug output callback, but I doubt that's what you want to do.
When debugging things like this, always look at the actual response you're getting from the server in your browser dev tools – if you had looked at that you would have seen the PHPMailer debug output in the responses.
Related
I am getting this error when trying to connect to an API in flutter to get user data. The API is remote, the phone has connection to the internet, I'm using an android phone to build the APP.
this is the error.
[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = address, port = 43798
for back end we are using PHP Laravel , but the API should be open to anyone who has the address at this point in development, so much so that the get request works both in Postman and in browser when calling.
As for the flutter function, this is the code being used.
Future<User> getUser(url) async {
print("here");
var params = {
"id": "01142",
};
Uri uri =
Uri.parse(url);
uri.replace(queryParameters: params);
final response = await http.get(
uri,
headers: <String, String>{
'Content-Type': 'application/json',
'Accept': "*/*",
'connection': 'keep-alive',
'Accept-Encoding': 'gzip, deflate, br',
'host': 'ipv4',
},
);
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
user = User.fromJson(jsonDecode(response.body));
print("NEW USER");
print(user);
return user;
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
throw Exception('Failed to load user');
}
}
According to back end Laravel isnt using SSL either, what might be the 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.
I use FCM for notification.
In firebase console i can send notification, but by PHP code not received and cant custom it
PHP code :
$data['TITLE'] = $title;
$data['TEXT'] = $text;
$fcmFields = array('to'=>$to,
'data'=>$data,
'priority'=>'high',
'time_to_live'=>$time);
$headers = array('Authorization: key='.API_ACCESS_KEY,'Content-Type: application/json');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fcmFields));
$result = curl_exec($ch);
curl_close($ch);
return $result;
Note: by this php code i can send notification android devices
Swift Code :
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Unable to register for remote notifications: \(error.localizedDescription)")
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("APNs token retrieved: \(deviceToken)")
}
}
#available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: #escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
completionHandler([])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: #escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
completionHandler()
}
}
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
let dataDict:[String: String] = ["token": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
}
1- I can send notification by google console and received but not prints anything in my app log
2- I can send notification to android devices by php codes but i cant send for ios devices
3- didReceiveRemoteNotification completely not work
Can you help me ?
I add 'notification' in PHP code and fixed
$fcmFields = array('to'=>$to,
'data'=>$data,
'notification'=>array('title'=>'x','body'=>'y'),
'priority'=>'high',
'time_to_live'=>$time);
I'm currently working with Stripe, trying to send a Stripe token to my backend using Alamofire and Heroku. My code is as follows:
func postStripeToken(_ token: STPToken) {
let URL = "https://limitless-fjord-73001.herokuapp.com/charge.php"
let params = ["stripeToken": token.tokenId,
"amount": Int(self.amountTextField.text!)!,
"currency": "usd"] as [String : Any]
Alamofire.request(URL, method: .post, parameters: params)
.responseJSON { response in
print(response.request as Any) // original URL request
print(response.response as Any) // URL response
print(response.data as Any) // server data
print(response.result as Any) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
}
The problem I'm having is that my response.result is printing as FAILURE (see Line 13 above). Everything else seems to be printing fine, including the token and the lines response.request, response.response, and response.data:
Optional(https://limitless-fjord-73001.herokuapp.com/charge.php)
Optional(<NSHTTPURLResponse: 0x600000425400> { URL: https://limitless-fjord-73001.herokuapp.com/charge.php } { status code: 500, headers {
Connection = "keep-alive";
"Content-Length" = 0;
"Content-Type" = "text/html; charset=UTF-8";
Date = "Mon, 29 May 2017 05:58:35 GMT";
Server = Apache;
Via = "1.1 vegur";
} })
Optional(0 bytes)
FAILURE
Any ideas on why I may be getting a failure? Thanks!
It is hard to tell what the problem is from the little you've shown us :)
However, this line:
Optional(<NSHTTPURLResponse: 0x600000425400> { URL: https://limitless-fjord-73001.herokuapp.com/charge.php } { status code: 500, headers {
And more specific this part of the line:
status code: 500, headers
Seems to indicate that you received an error code 500 from your backend, meaning that there was a server side error of some sort.
So, is there a log file somewhere on your server that you could look at and see if it tells you something?
Hope that gives you something to work with.
I configured my app:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let pushSettings: UIUserNotificationSettings = UIUserNotificationSettings(
forTypes:[.Alert, .Badge, .Sound],
categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(pushSettings)
UIApplication.sharedApplication().registerForRemoteNotifications()
return true
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("My token is: \(deviceToken)");
}
// Failed to register for Push
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print("Failed to get token; error: %#", error) //Log an error for debugging purposes, user doesn't need to know
}
Copy my device token, to my python script:
import time
from apns import APNs, Frame, Payload
apns = APNs(use_sandbox=True, cert_file='NodesDownCert.pem', key_file='NodesDownKey.pem')
# Send a notification
token_hex = 'xxx'
payload = Payload(alert="Hello World!", sound="default")
apns.gateway_server.send_notification(token_hex, payload)
I ran script, it didn't return errors, but i haven't received notifications at my Ipad. I tried php script from this tutorial, script returns "Message successfully delivered", but i'm still not receive any message. Php code here.
Any ideas how to debug or what is wrong ?