0

I have a small PHP script on Amazon EC2 which is supposed to send the OTP to the mobile number. However, the response we are getting is NULL. Below is my PHP code:

<!DOCTYPE html>
<html>
<body>

<?php
/* initialize an array */
$paytmParams = array();

/* Enter user's 10 digit mobile number */
$paytmParams["phone"] = "1234567890";

/* Enter your client id here */
 $paytmParams["clientId"] = "some-user";
/* enter resource scope */
$paytmParams["scope"] = "wallet";

/* enter response type, the value here will be 'token' */
$paytmParams["responseType"] = "Token";

/* prepare JSON string for request */
$post_data = json_encode($paytmParams, JSON_UNESCAPED_SLASHES);

/* for Staging */
$url = "https://accounts-uat.paytm.com/signin/otp";

//$auth = "Basic " . base64_encode("some-user" . ":" . "bWPstgyLRfz71GYtgcAbsx1nSPtCqpL9");

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
       
//curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: " . $auth));
$response = curl_exec($ch);
        if (!$response) {
   die(curl_error($ch));
}
$response=json_decode($response,true);
if($response['status']=='SUCCESS')
$responseData=array('success'=>'1', 'data'=>$response,'message'=>" The OTP has been sent to your mobile");
else
$responseData=array('success'=>'0', 'data'=>$response,'message'=>"Oops...We are unable to send the OTP at this moment.");
$userResponse = json_encode($responseData);
print $userResponse;


?>

</body>
</html>

The output that we are receiving for the above script is :

Could not resolve host: accounts.paytm.com

However, with the same parameters on Postman, the OTP is received correctly. I think I have set up the server correctly - apache, PHP. I am pretty new to server-side scripting so am not sure what is causing the issue. My guess is there is some configuration issue on the server. Please help me in resolving the issue. Thanks for your help in advance.

Shiny
  • 115
  • 1
  • 9
  • 2
    Does this answer your question? [amazon ec2 instance unable to resolve host](https://stackoverflow.com/questions/22614374/amazon-ec2-instance-unable-to-resolve-host) – ADyson Feb 26 '21 at 16:04
  • Hi, I edited the /etc/hosts file as per the responses in the suggested link. Unfortunately, that did not solve the issue. I still get the same error. – Shiny Feb 26 '21 at 16:25
  • Did you try any of the other suggestions as well? – ADyson Feb 26 '21 at 16:34
  • Yes, I have tried most of the suggestions which refer to editing the /etc/hosts files to include the same name as in /etc/hostname against 127.0.1.1. I am still facing the same issue. – Shiny Feb 26 '21 at 16:58
  • what about all the stuff about DNS options etc? e.g. https://stackoverflow.com/a/34902383/5947043 or https://stackoverflow.com/a/22614664/5947043 – ADyson Feb 26 '21 at 17:16

0 Answers0