I'm trying todo a simple curl with a hashtag in target url - but getting errors.
I know this script works, i've used it many times before.
<?php
error_reporting(E_ALL);
$curl = curl_init('http://tools.pingdom.com/fpt/#!/d3YvU8/http://www.nginx-hosting.co.uk');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
if ($result == ("")) {
echo ("Nothing to curl");
}
else {
echo $result;
}
?>
Here is the above script in action: http://www.nginx-hosting.co.uk/curl_test.php
As you can see the ouput is nothing like it's supposed to be. I ran the same command through SSH :
curl http://tools.pingdom.com/fpt/#!/d3YvU8/http://www.nginx-hosting.co.uk
But get this error message -bash: !/d3YvU8/http: event not found
I assume this is because the target url has an exclamation mark in it or a hashtag.
Could someone point me in the right direction please. Thanks in advance
I just tried your script it works just fine, about -bash: !/d3YvU8/http: event not found error you should use quotes like: curl '
http://tools.pingdom.com/fpt/#!/d3YvU8/http://www.nginx-hosting.co.uk'
Related
I've been struggling since 1 month trying to find how every browser, every mobile phone except iPhone, can accept my cURL URL request but not on iPhone?
I mean, when I go to URL to call the cURL (via the URL which is a PHP file, it always give me an empty query).
I tried every possible way, user-agent, header, SSL, with cURL option and nothing working.
Every browser working and also every Samsung phone, why does iPhone ignore it?
I also tried it with Safari that I've downloaded for Windows, and work well.
Anybody already had these issues?
I just don't know what to do, there nothing to help me find the problem, no tools... :(
Here is the cURL call (this is a function but you got it how i call it):
private function __request($url, $post = false, array $headers = NULL, $decode_json = true){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if($post){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($post) ? http_build_query($post) : $post);
}
if($headers){
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$data = curl_exec($ch);
if($decode_json){
return json_decode($data);
} else {
return $data;
}
}
Thanks for any help
I have two PHP sites, an API site (x.php) and another, which calls the API site with CURL (y.php)
The x.php looks like this:
if (isset($_POST['testconnection'])) {
return "ok";
}
And the y.php like this:
$host = "https://there.is.the/x.php";
$command = array (
"testconnection" => "testconnection"
);
$ch=curl_init($host);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($command));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,180);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
As you can see in the example, I would like to get the return string from x.php in the y.php, but I get an empty string in the answer: string(0) ""
I think it would be: string(2) "ok"
I have replaced the return to echo in x.php but without success.
Sorry if it is a noob question, I'm quite new in curl.
Replace
return "ok";
With
echo "ok";
Your script is exiting with return value, but nothing is output as a response.
A thing to note is that web server must have permissions to access the x.php. Verify that the script is able to execute. Permission problems often result in a blank page.
Tip: Use Postman to test REST APIs. You could shoot the post query against your x.php and see what comes back, eliminating the curl part being wrong.
I am trying to use curl with PHP to execute a POST call from PHP but always I get page error
this is my code
if($curl = curl_init()){
curl_setopt($curl, CURLOPT_URL, 'http://marcelotavarez.com/freeodds.aspx');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "CallbackMethod=GetLines&Parm1=20170110&Parm2=2&Parm3=0&CallbackParmCount=3&__WW EVENTCALLBACK=CustomerCallback&__WWEVENTTARGET=Page&__VIEWSTATE=/wEPDwUKLTQwNjM5NzY1NmRkOa+UqFoVFF+BzUdMUBBH1ahGsWQ=&__VIEWSTATEGENERATOR=BB49A8FA&");
$out = curl_exec($curl);
echo "===\n $out \n====\n";
$out = str_replace("\"","",$out);
}
Using the inspector from Chrome I checked the header that I need to use to do the POST Call and these are:
CallbackMethod:GetLines
Parm1:"20170110"
Parm2:2
Parm3:0
CallbackParmCount:3
__WWEVENTCALLBACK:CustomerCallback
__WWEVENTTARGET:Page
__VIEWSTATE:/wEPDwUKLTQwNjM5NzY1NmRkOa+UqFoVFF+BzUdMUBBH1ahGsWQ=
__VIEWSTATEGENERATOR:BB49A8FA
Any time that I use this code just I get the error page
Any cluees or any help , pls
TIA
I need to ask you a question where is CallbackMethod=GetLines
GetLines function , I think must be in your code to be executed after response back
I want to create simple code for crawl using curl.. my code like this..
but it's still route to static ip 10.151.34.14... i change my url.. but it's still to 10.151.34.14.
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"http://aampuh.blogspot.co.id/");
curl_setopt($curl, CURLOPT_POSTFIELDS, "foo");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
echo curl_exec($curl);
if(curl_errno($curl))
{
echo 'Curl error: ' . curl_error($curl);
}
?>
enter image description here
this is my output... please help me... i'm so confuse until now.
It seams there is a proxy configured in your environment.
echo curl_getinfo($curl, CURLOPT_PROXY);
curl_setopt($curl, CURLOPT_PROXY, '');
Those are often defined in environment variables, see print_r($_ENV) for details.
I need upload a file using php. I have the following code that I am using
<?php
$file = realpath('hello_world.jpg');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.newocr.com/v1/upload?key=*My key*');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '#'.$file));
$result = curl_exec($ch);
echo $result;
curl_close ($ch);
?>
On executing I get the error msg
{"status":"error","message":"File must be uploaded.
https://www.newocr.com/api/"}
But when I manually make a form and upload the image using multipart it works fine. Is something wrong with my code or the issue is with the API
Executing it from command line like this
curl -X POST -F "file=#hello_world.jpg" http://api.newocr.com/v1/upload?key=*my api key*
Works fine
curl_setopt($ch, CURLOPT_UPLOAD, TRUE);
Now, it is giving:
404 Page Not Found
The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below.
Visit the Home Page
I had the same problem.
Solution:
<?php
$result = exec('curl -H "Expect:" -F file=#'.realpath($file).' http://api.newocr.com/v1/upload?key=KEY');
$result = json_decode($result, true);
return $result;
?>