I am using php curl to ping and post data to a url. But it is not working.response of url is "not found" this comes when the posting url is "http://example.com/conversion_get/"
I suspect it was because of .jpg in curl url.
I am using same code in same application to post data. but it works fine. Can any body help me to sort out this issue?
My code:
$kps="6789345607655ABF5k23929ocern46789345607655ABF5k23929ocern4";
$url="http://example.com/conversion_get/pixel.jpg";
$ch = curl_init();
if (!$ch){die("Couldn't initialize a cURL handle");}
$ret = curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "kp=".$kps);
$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlresponse = curl_exec($ch);
curl_setopt($ch, CURLOPT_HEADER, 0);
if(curl_errno($ch))
echo 'curl error : '. curl_error($ch);
if (empty($ret)) {
curl_close($ch);
} else {
$info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
$ns= $curlresponse;
}
Related
$ch = curl_init('localhost/beater');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 3); //timeout in seconds
header('Content-Type: application/json');
echo curl_exec($ch);
// Check if any error occurred
if(curl_errno($ch))
{
echo curl_errno($ch);
//header('Location: error');
}
As the title says, instead of setting the domain every time, how can I just type the PHP file? (As it's on my domain).
If I set it to $ch = curl_init('beater'); or $ch = curl_init('beater.php'); I just get "Error 3" which is a malformed URL
I hope you guys can help!
I am using curl reques to get report of sms but facing some issues. i have also ckecked by encoding url but still same issue.
400 bad request is being shown.
$url="http://api.smscountry.com/smscwebservices_bulk_reports.aspx?user=&passwd=&fromdate=19/04/2017 00:00:00&todate=19/04/2017 23:59:59&jobno=60210892"; //callbackURL=http://www.jouple.com/marketing/public/save/sms
$ch = curl_init();
if (!$ch){
die("Couldn't initialize a cURL handle");
}
$ret = curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// curl_setopt ($ch, CURLOPT_POSTFIELDS,
// "User=$user&passwd=$password&sid=$senderid");
// $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//If you are behind proxy then please uncomment below line and provide your proxy ip with port.
// $ret = curl_setopt($ch, CURLOPT_PROXY, "PROXY IP ADDRESS:PORT");
$curlresponse = curl_exec($ch); // execute
// print_r($ch);die;
if(curl_errno($ch))
echo 'curl error : '. curl_error($ch);
if (empty($ret)) {
// some kind of an error happened
die(curl_error($ch));
curl_close($ch); // close cURL handler
} else {
$info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
}
This happens when you have whitespaces in URL. You have to escape url. Follow the below code
<?php
$url="http://api.smscountry.com/smscwebservices_bulk_reports.aspx/"; //callbackURL=http://www.jouple.com/marketing/public/save/sms
$url2= "?user=&passwd=&fromdate=19/04/2017 00:00:00&todate=19/04/2017 23:59:59&jobno=60210892";
$ch = curl_init();
$url = $url . curl_escape($ch, $url2);
if (!$ch){
die("Couldn't initialize a cURL handle");
}
$ret = curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// curl_setopt ($ch, CURLOPT_POSTFIELDS,
// "User=$user&passwd=$password&sid=$senderid");
// $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//If you are behind proxy then please uncomment below line and provide your proxy ip with port.
// $ret = curl_setopt($ch, CURLOPT_PROXY, "PROXY IP ADDRESS:PORT");
$curlresponse = curl_exec($ch); // execute
// print_r($ch);die;
if(curl_errno($ch))
echo 'curl error : '. curl_error($ch);
if (empty($ret)) {
// some kind of an error happened
die(curl_error($ch));
curl_close($ch); // close cURL handler
} else {
$info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
}
After this you will face a error invalid content length. Uncomment the line CURLOPT_POSTFIELDS and pass correct credentials. Definitely it will work.
You can add just urlencode() to your parameters like msg and mobile :
$sms = "Dear User, Your OTP for trip is $otp CSPL";
$sms = urlencode($sms);
$mobile = urlencode($mobile);
$url = "yoururl";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$responseJson = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
I tried accessing a website using curl and it just output Object moved to here. I used curl_error but doesn't show any errors.
$url = "https:somewebsite.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // Accepts all CAs
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
//curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
if(curl_error($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo $output;
?>
Here is the url below, tried both with the method file_get_contents and curl...doesn't work from php script but works fine with postman.
Any idea why so???
https://query.yahooapis.com/v1/public/yql?q= select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text="(28.56,77.32)") and u='c'&format=json
cURL request is as follows:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
// convert response
$output = json_decode($output);
// handle error; error output
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
var_dump($output);
}
echo curl_error($ch);
curl_close($ch);
Try with this one. The difference is that the url is url encoded:
$url = 'https://query.yahooapis.com/v1/public/yql?q=%20select%20*%20from%20weather.forecast%20where%20woeid%20in%20(SELECT%20woeid%20FROM%20geo.places%20WHERE%20text=%22(28.56,77.32)%22)%20and%20u=%27c%27&format=json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$output = curl_exec($ch);
I need to fetch data from myallocator.com. I have his api address api.myallocator.com,
but when I send my data to them, it failed. I wrote some code for that which is shown below. Basically that pms property management system site.By that you can manage your property with his api.
$url = "http://api.myallocator.com/";
$xmlRequestString='<?xml version="1.0" encoding="UTF-8"?>
<GetProperties>
<Auth>
<UserId>"xxxxxxx"</UserId>
<UserPassword>"xxxxx"</UserPassword>
<VendorId>"xxxxxxx"</VendorId>
<VendorPassword>"xxxxxxxx"</VendorPassword>
</Auth>
</GetProperties>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequestString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$data = curl_exec($ch);
echo $data;
curl_close($ch);
Here Is the example of php curl with post try this
<?php
$ch = curl_init();
// set your site url
curl_setopt($ch, CURLOPT_URL,"http://testmysite.com/");
curl_setopt($ch, CURLOPT_POST, 1);
// postvar1, postvar2 .. are the parameters to send with post
curl_setopt($ch, CURLOPT_POSTFIELDS,
"postvar1=value1&postvar2=value2&postvar3=value3");
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
if ($server_output == "OK") { ... } else { ... }
?>