cURL and PHP post request - php

I am new at cURL and can`t understand. I have for example this code
curl -d '
{
"data": {
"title": "Bubble Nebula",
"body": "It`s found today at 21:00",
"icon": "https://peter-gribanov.github.io/serviceworker/Bubble-Nebula.jpg",
"image": "https://peter-gribanov.github.io/serviceworker/Bubble-Nebula_big.jpg",
"click_action": "https://www.nasa.gov/feature/goddard/2016/hubble-sees-a-star-inflating-a-giant-bubble"
}
"to": "YOUR-TOKEN-ID"
}' \
-H "Content-Type: application/json" \
-H "Authorization: key=AAAAaGQ_q2M:APA91bGCEOduj8HM6gP24w2LEnesqM2zkL_qx2PJUSBjjeGSdJhCrDoJf_WbT7wpQZrynHlESAoZ1VHX9Nro6W_tqpJ3Aw-A292SVe_4Ho7tJQCQxSezDCoJsnqXjoaouMYIwr34vZTs" \
-X POST "https://fcm.googleapis.com/fcm/send"
How should i do it work well with php?

Most of the time I just use file_get_contents() for my requests, but that trick is sadly only for GET requests.
However, I recently discovered a new trick that can be used with Post and Get requests(Including everything else that curl can) and still avoids the horrible php library phpcURL, And the best part is, that you don't even need to change your curl command. Try the code below.
<?php
$curl = "your curl command" // paste your curl command here
exec("$curl > curloutput.txt");
$response = file_get_contents("curloutput.txt");
echo($response);
?>
This code should execute your given curl command and return the output. Yes, I know this sounds like a really janky method but it works every time bugless and it is super easy to use.

Related

How to use cURL in HTML?

Probably a stupid question but how on earth does one use cURL within HTML?
I'm trying to set up a Coinbase API and I'm getting error instantly, Is cURL only available in certain websites, React etc? Or can this be used in standard HTML/PHP?
Obviously the first error I'm getting is "unexpected POST".
Coinbase instructions aren't very clear to someone whos never used React or cURL before.
I would be extremely grateful if someone could just explain it a little clearer :)
My undertanding here is that once the "Pay with Crypto" submit button has been clicked I'm assuming this "data.JSON" file is included with the POST info? and it should submit the details to a hosted checkout page, including the .json details/price, right? This might be wrong but I feel I'm on the right track.
This is the code in my html page...
<?php
curl -X POST https://api.commerce.coinbase.com/charges/ \
-H "Content-Type: application/json" \
-H "X-CC-Api-Key: MY_API_KEY" \
-H "X-CC-Version: 2018-03-22" \
-d "#data.json"
?>
Here I have my "data.JSON" file with this code...
{
"name":"TZ",
"description":"Selected Repair Service",
"pricing_type":"<?php echo $fetch['price']; ?>"
}

Facebook graph API: mark message as read

I get message conversations via Facebook graph API which looks like:
https://graph.facebook.com/' + id + '/messages?fields=message
and I want to mark as read the message but I can't find how to in documents.
please, can someone point me to some examples?
You only have read access to the Inbox via the API. So this is not currently possible.
You can set typing indicators or send read receipts using the API, to let users know you are processing their request.
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"<PSID>"
},
"sender_action":"typing_on"
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
Check below.
sender action = mark_seen..
I am using it and its working fine..
https://developers.facebook.com/docs/messenger-platform/send-messages/sender-actions/
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id":"<PSID>"
},
"sender_action":"mark_seen"
}' "https://graph.facebook.com/v2.6/me/messages?access_token=
<PAGE_ACCESS_TOKEN>"

How to send push to specific devicetoken on php function

I'm Using Ionic Framework V1.
I've already get push notifications through Postman using
and I've already save all devicetokens in my DB, but i'm stuck at getting any push for specific devices in php functions.
curl -X POST -H "Authorization: Bearer API_TOKEN" -H "Content-Type: application/json" -d '{
"tokens": ["DEV_DEVICE_TOKEN"],
"profile": "PROFILE_NAME",
"notification": {
"message": "This is my demo push!"
}
Example:
public function confirmAction($request){
$action = $this->find($request->idtblAction);
$action->idtblStatus=1;
if($action->save()){
//I need to send notification in this part
return Response::json(array('success'=>'true'));
}else{
return Response::json(array('success'=>'false'));
}
}
Ionic io uses Bearer key and profileapp
Any idea?
I've already solve this without using php. I did it through my internal ionic app code.
Thank you to everybody!

How to POST data to php from ash (bash)

I have url (www.blabla.web.id/proses_data.php) online. And I want to submit data to that url from my bash script. I'm using ash, bash inside OpenWRT.
I'm trying this technique,
#!/bin/sh
elinks -dump http://www.blabla.web.id/proses_data.php?data=thisisthedata
But it use GET method. How to use POST method?
elinks is a program for browsing the web in text mode. you may not post data throgh it.
but Linux provide beautiful tools for POST data
with this nice and little command
curl --data "param1=value1&param2=value2" http://hostname/resource
Also POST if web response in JSON then
curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" http://someHostName/someEndpoint -d '{"id":"IDVALUE","name":"Mike"}' | grep }| python -mjson.tool
Aslo some little trick here
Add this function in php script
function getInput() {
$fr = fopen("php://stdin", "r");
while (!feof ($fr)) {
$input .= fgets($fr);
}
fclose($fr);
return $input;
}
$takethis = getInput();
Now in bash do like
echo 22333333 | php my.php

Restler3: DELETE Body JSON

I really don't understand what I should do to make a DELETE request.
I want to use JSON as in/output only, so also a DELETE request should receive JSON.
But that doesn't make the goal:
public function delete($request_data = NULL)
$request_data is nil every time. I'm trying it by using cURL:
curl -X DELETE http://…/API/index.php/test.json -H "Content-Type: application/json" -d '{"key":"test","value":"1337"}'
Can someone explain that to me?

Categories