I was trying to work on cloudflare api and I have found this in their documentation. Unfortunately I have no Idea how I can use this in fsockopen or through curl. Here is the example of POST Request. I just need to know how I can make a request with below data as POST using curl or fsockopen
curl https://www.cloudflare.com/api_json.html
-d 'a=cache_lvl' \
-d 'tkn=8afbe6dea02407989af4dd4c97bb6e25' \
-d 'email=sample#example.com' \
-d 'z=example.com' \
-d 'v=agg'
Here is the link to cloudflare
https://www.cloudflare.com/docs/client-api.html#s4.2
Try this one:
$ch = curl_init("https://www.cloudflare.com/api_json.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
// handling of -d curl parameter is here.
$param = array(
'a' => 'cache_lvl',
'tkn' => '8afbe6dea02407989af4dd4c97bb6e25',
'email' => 'sample#example.com',
'z' => 'ex'
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
$result = curl_exec($ch);
curl_close($ch);
print $result;
Related
I`m using weasyprint by aquavitae for generating PDFs for my Laravel application via cURL
curl -X POST \
-H Content-Type:text/html \
-T ./test.html http://127.0.0.1:5001/pdf?filename=test.pdf \
-o test.pdf
This is an example of cURL request to a weasyprint which gives me a good responce, but when u try to do this in my PHP:
$path_to_file = 'd:/index.html';
$ch = curl_init();
$headers = array(
"Content-Type:text/html"
);
curl_setopt($ch, CURLOPT_URL, 'http://192.168.99.100:5001/pdf');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'datafile' => curl_file_create($path_to_file , mime_content_type($path_to_file), basename($path_to_file))
]
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
I get my responce as a line and when I want to responce it to a browser or into a file I get some information about HTML file I sent:
PDF file I get with PHP cURL
tho my HTML file contains only
<h1>hello world</h1>
I can see something like that when I use Postman too.
I think that there`s some difference beetwen how I send file with CMD cURL and PHP cURL.
Do you guys have any ideas?
How do I use the following example curl to send an actual SMS with PHP?
// -- Sending Direct SMS --
curl -X "POST" "https://api.ringcaptcha.com/APP_KEY/sms" \
-d "api_key=API_KEY" \
-d "phone=TO_NUMBER" \
-d "message=Hi there! This is a test message from
RingCaptcha."
At last Worked :)
$data = array(
'api_key'=>'{api_key}',
'phone'=>'{number}'
);
$string = http_build_query($data);
$ch = curl_init("https://api.ringcaptcha.com/{key}/code/sms");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
print_r($server_output);
Teaching myself some Facebook feed posting via PHP and I'm trying to figure out how I would execute this curl HTTP POST via the the PHP curl command, any suggestions?
curl -X POST \
-F 'message=Post%20with%20app%20access%20token' \
-F 'access_token=YOUR_APP_ACCESS_TOKEN' \
https://graph.facebook.com/4804827/feed
It's found here
This is how to do it:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/4804827/feed");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'message' => 'Post with app access token',
'access_token' => 'YOUR_APP_ACCESS_TOKEN'
));
echo curl_exec($ch);
curl_close($ch);
I recommend looking at the documentation:
http://www.php.net/manual/en/function.curl-init.php
http://www.php.net/manual/en/function.curl-setopt.php
can any one help me to convert following curl code to php curl script?
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/xxx/SMS/Messages.xml' \
-d 'From=%2Byyyy' \
-d 'To=%2Bxxxx' \
-d 'Body=Dear%2C+Plz+wake+up%3B+it'\''s+time+4+SAHERI.%0D%0AYour+1+night+sacrifice+will+make+thousands+night+wonderful+by+the+grace+of+almighty+ALLAH.%0D%0A%0D%0A-biplob+(%2Bxxxxx)' \
-u xxx:yyy
best regards
MD Kamrul Hassan
The options you'd need set on your curl handle are as follows.
curl_setopt($ch, CURLOPT_URL, 'https://api.twilio.com/2010-04-01/Accounts/xxx/SMS/Messages.xml');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('From' => 'blah', 'To' => 'blih', 'Body' => 'Please wake up whatever'));
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
I want to access an API provided by Lymbix sentiment via PHP. The cURL command given is
curl -H "AUTHENTICATION:MY_API_KEY" \
-H "ACCEPT:application/json" \
-H "VERSION:2.1" \
http://gyrus.lymbix.com/tonalize \
-d "article=This is a sample sentence, does it make you happy? \
&return_fields=[]"
How would I run the above in PHP?
Thank you.
I hate to feed the trolls, but i was bored. You really should do some legwork on these things first, and also accept (checkmark) answers when they are right, or got you really close.
<?php
$ch = curl_init();
$data = array('article' => 'This is a sample sentence, does it make you happy?', 'returnfields' => '[]');
$headers = array ('AUTHENTICATION'=>'MY_API_KEY','ACCEPT'=>'application/json','VERSION'=>'2.1');
curl_setopt($ch, CURLOPT_URL, "http://gyrus.lymbix.com/tonalize");
curl_setopt($ch, CURLOPT_HTTPHEADERS,$headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
curl_close($ch);
?>
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://gyrus.lymbix.com/tonalize" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt($curl, CURLOPT_POST, true );
curl_setopt($curl, CURLOPT_POSTFIELDS, "article=This is a sample sentence, does it make you happy?&return_fields=[]");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"ACCEPT:application/json\n",
"VERSION:2.1\n",
"AUTHENTICATION:MY_API_KEY",
));
$result = curl_exec($curl);
curl_close($curl);