Reputation: 11
It's not sending the post request. I am not sure as in why, or what I'm doing wrong.
This is the API in the database:
//servapi added to code for clarity
$servapi = "https://(hidingwebsiteforthispost).com/api.php?key=(my_key)&service=31&action=order&profile=[link]&amount=[amount]"
//original code
$arrayFind = array(
'[link]',
'[amount]'
);
$arrayReplace = array(
$link,
$quanity
);
$APILink = $servapi;
$APILink = str_replace($arrayFind, $arrayReplace, $APILink);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $APILink);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_exec($ch);
curl_close($ch);
Added by moderator:
User is verifying whether a POST request is successful by reviewing his account on the destination server. If successful, a new order will be started under his account. When he uses the API string from requestmaker.com, a new order is created, but when he runs the above code, a new order is not created.
When using var_dump to inspect the returned packet from curl_exec($ch)
, user states that the response is empty.
User has also updated his code to set CURLOPT_POST to true.
Upvotes: 1
Views: 2031
Reputation: 1065
In addition to @nvisser's suggestion, you should also capture and review the response from the curl request. Change your curl_exec
as follows:
$response = curl_exec($ch);
Because you have set CURLOPT_RETURNTRANSFER to TRUE, your curl_exec encapsulates all responses as a string and returns them to a variable of your choice.
Output the response and you will likely find more information to help you diagnose the issue.
Added after discussion in comments:
Here is what we should do:
Since you do not have control over the network, try installing and activating the web server on your virtual private server so that you can receive and process requests at http://localhost/fakeServer.php
Once you have installed Apache2 or NGINX and set it up, create a small program called fakeServer.php
at the root of that web directory, and set the API url to http://localhost/fakeServer.php
. Inside that script, make a log that outputs the content of the $_POST
headers every time the script is run.
In this way, you can prove whether your script is sending out requests and what they look like to the receiving server. This will help you debug your script to use the API class and verify that all your code is formatted well and operating correctly.
Have fakeServer.php
output a response and check for that response in your program. If all is working well, the output from fakeServer.php
will end up in your $response
variable.
If all is not working well, we have more control over the test environment to find the problem.
Upvotes: 1
Reputation: 821
You're not actually doing a post request, you'll want to add
curl_setopt($ch, CURLOPT_POST, true);
in order to send a POST request.
See the curl documentation and specifically the curl_setopt documentation for more information.
Upvotes: 1