Have made and deployed an app on an AWS EC2 instance, and accessing the app via ip_address:port, where ip_address is the elastic ip associated with the instance.
I am able to make API calls to this app using postman, and via cmd.
However, when I try to make POST request using PHP Curl on Wordpress (hosted on Bluehost), I keep getting the
Failed to connect to ip_address port XXXX after 0 ms: Connection refused.
Any ideas of what I might be missing?
'''php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http:ip_address:8000/payments/accounts/v1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
CURLOPT_TIMEOUT => 1000,
CURLOPT_CONNECTTIMEOUT => 1000,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_CUSTOMREQUEST => 'POST',));
print_r(curl_error($curl));
curl_exec($curl);
curl_close($curl);
'''
Getting this response
'''code
Failed to connect to id_address port 8000 after 0 ms: Connection refused
'''
Using the redacted ip and a slightly modified version of your code as follows:
$url='http://X.XXX.XX.XX:8000/payments/accounts/v1';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 1000,
CURLOPT_CONNECTTIMEOUT => 1000,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST=>true
)
);
$res=curl_exec( $curl );
curl_close( $curl );
printf('<pre>%s</pre>',print_r( $res, true ));
Yields:
{"detail":"Authentication credentials were not provided."}
Perhaps if you were to actually include and submit some post data in the CURLOPT_POSTFIELDS option you might find a different response.
Related
I'm getting 410 - unregistered failures. Even I am deleting my unregistered tokens. It was working fine for years and recently facing more number of issues.
I am passing over the bundle id properly.
if (!defined('CURL_HTTP_VERSION_2_0')) {
define('CURL_HTTP_VERSION_1_0', 3);
}
$url = "{$base_url}/3/device/{$appIosRegId}";
// headers
$headers = array(
"apns-topic: {$app_bundle_id}",
'Authorization: bearer ' . $jws
);
// other curl options
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
CURLOPT_URL => $url,
CURLOPT_PORT => 443,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $varData,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_HEADER => 1,
CURLOPT_SSL_VERIFYPEER => false
));
I have not made changes related notifications and cross checked with all the programs. And everything set was proper only.
Does this needs any upgrade?
My current curl version is curl 7.83.1 (Windows) Release-Date: 2022-05-13
I want to show my data on my CRM using PHP with curl and also using API.
If there is any other method. You can kindly show it to me
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://b.maxmind.ma/api/leads",
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(
"authtoken: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyfdfdiOjE1ODEwODk2MjJ9.Selc36cmT3XyXH6cGdJ3SN-332kx7"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
the response show : error code: 1020
I think the problem is that the website you are trying to request is protected by Cloudflare.
When i try by the postman , this is the header response a get :
The error code 1020 you got is from cloudflare .
First, you can try using this solution that bypasses the Cloudflare problem
KyranRana/cloudflare-bypass
If not working, in this case, you must contact the site owner to remove the block (more here)
I'm going to ask a question that's already been asked a lot, but I can't find a solution that works on my server.
I make a call with PHP on an API where I am correctly identified. I get the famous error 52 (Empty reply from server).
I tried all the parameters indicated on Stack but nothing works. I'm on a Ngnix server with an SSL Lets encrypt.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://xxx/route/rest?=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 100,
CURLOPT_TIMEOUT => 300,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "app_key=" . env('APP_KEY')
));
$response = curl_exec($curl);
If you could help me, I would be very grateful.
Have a nice day
Eliott
I have been working on some code to automate an update to a specific task in AtTask using the API. I am finding some problems using PHP's CURL request for a PUT command. Here is a copy of the code:
$updateURL = "https://[COMPANYURL].attask-ondemand.com/attask/api/v4.0/task?updates={'ID':'TASKID','name':'Ok. Here we go again','commitDate':'2015-10-27T17:30'}";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $updateURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => array(
"sessionid: " . $this->sessionId
),
));
$attask_update_json = curl_exec($curl);
The code executes with out any errors being reported, but the return response is blank. I have verified my URL using postman and it processes correctly, but I can not get the code to process in PHP. Any help would be appreciated.
I need some help, here the code :
<?php
$curl_options = array (CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_ENCODING => "",
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 60,
CURLOPT_MAXREDIRS => 5 );
$handle = curl_init("http://my.awesome.subdomain.com");
curl_setopt_array($handle, $curl_options);
$content = curl_exec($handle);
print_r(curl_error($handle));
print_r($content);
die();
my.awesome.subdomain.com is a vhost. On the same machine i have another.awesome.subdomain.com which is on the same machine.
Via SSH, if i do $> curl my.awesome.subdomain.com I get the answer i expect. But when i use this code, i get "Connection timed out after 30180 milliseconds"
Thanks for help and sorry for my writing errors.