Send Request from server to ngrok server in PHP - php

So I want to send a request from my server to NGROK server and it return null.
but when I check the URL, it return something.
I've tried so many ways, but it still doesn't work for me
this is my code
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
I also tried request to another server (not NGROK) with same code, and it works. this is only happen on ngrok

Related

Cancel Shipstation API Issue PHP

I'm trying to cancel the order from Shipstation for That I've write a code
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/orders/".$order_id,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_USERPWD => "$public_key:$private_key",
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
echo "here";
now when I run this API it returns nothing no error no issue no success message same order is also not deleted from Shipstation when I try to pass wrong Public or Private key then it gives me an Error
401 Unauthorized
it means that API call is going correctly because I'm getting response but when I pass the correct creds then it gives no response.
Edit
Now I'm trying
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://ssapi.shipstation.com/orders/".$order_id,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => array(
"Host: ssapi.shipstation.com",
"Authorization:Basic __MY_AUTH_HERE__",
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Now it is giving me an Error
{"Message":"Authorization has been denied for this request."}
where I've created my Auth like
$auth = base64_encode($username_api_key.":". $password_api_secret);
What is the issue and how to fix that?
Thanks

Accessing exchange rates converted into CAD from USD isn't working

I'm not sure why the test program below isn't getting the response from the API. Here is the document for the API. It's working absolutely fine on the provider's playground. Running the test program below doesn't do anything at all.
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.apilayer.com/exchangerates_data/convert?to=CAD&from=USD&amount=1",
CURLOPT_HTTPHEADER => array(
"Content-Type: text/plain",
"apikey: av5CJRrOA2Rclj4fai3UZF5NT7F9HmPr"
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>

PHP Curl GET request not working but works fine in POSTMAN

I am trying to get product data from google merchant center (google shopping ), my curl command works fine on postman, but not on php. Please help me
On postman:
On Php:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://shoppingcontent.googleapis.com/content/v2.1/436306321/products',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ya29.a0ARrdaM8TK4rZeVRnsj9MgcFg3STE1EqGvwj20J-REq8f6poCzGIv2MzUIegdSP1DDa_-HQpHIQNBTU6Rnxf7HsnWCjwkP7_pwkp-kr5zm0o0Z6EuZCVa4IdwHzX7MGM8SQ-94Vkxps4JRSbkgplYo4w1K8lPwQ'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

PHP - GET request works in Postman, but not with cUrl

There's a free weather API in my country that I want to use to get rain data. The request is simple https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826 and there's no authentication. If I try the request using Postman, my browser or AJAX, it works fine and I get the results I need. However, using cURL, I get nothing.
Here's the PHP code that I tried:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I have the cURL.dll installed and tested in another server, but it didn't work.
Is there a problem with the code or is it the API that blocks PHP requests?
its look like this website looking for user-agent header.
try this:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://apitempo.inmet.gov.br/estacao/2021-05-03/2021-05-06/A826',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'User-Agent: something'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

403 The request could not be satisfied response when hitting the Cowin API

403 ERROR The request could not be satisfied cowin API
getting above error while hitting the cowin API
This is working fine on local machine and post man
here is my code
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByDistrict?district_id=512&date=16-05-2021%0A',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>

Categories