Sending POST request data stored in a variable using curl, sends $variable instead json data.
P=`/usr/bin/sudo /usr/bin/curl -X POST -H "Content-Type:application/json" --data-urlencode $data http://127.0.0.1/abc.php`
Trying to send POST request to php, but it receives $data instead json data{"abc":"11","xyz":"20"}.
Had try with '$data', "$data", \'$data\' and \"$data\", where $data = {"abc":"11","xyz":"20"}
Please give an example that works. Thanks in advance.
P=`/usr/bin/sudo /usr/bin/curl -X POST -H "Content-Type:application/json" -d "$O" http://127.0.0.1/abc.php` solves issue.
If you add single quote it won't expand variable, so it requires to add double quote.
I suggest all time reload page or script, as I have seen if you not reload, it work with your last change instead new one.
Related
Using third party service; they are providing webhook services; I have given my url to send the response on my page:
Example: https://abcd.com/postback.php
Getting curl response on postback.php; to read the POST data; I am using following code:
$postdata = file_get_contents("php://input");
but not able to read the header & data content.
Sample Response that they are sending:
curl -L -X POST 'https://abcd.com/postback.php' -H 'x-changenow-signature: xcgh123POPI6727kslsldjsd' -H 'Content-Type: application/json' --data-raw '{"status":"finished","payinHash":"31mrEanXyv","payoutHash":"485d8dz","payinAddress":"3Nups0bF","payoutAddress":"1K1LcQSPZVj2dM","fromCurrency":"sol","toCurrency":"btc","amountSend":0.06676453,"amountReceive":0.00010273,"refundAddress":"Bk1qVzc3GULcJQ0NoW4DsepRJHevzAD8ynznEQ1aNzGq","id":"f7bed8a9e4a350","updatedAt":"2022-06-23T11:22:38.728Z","createdAt":"2022-06-23T11:09:56.403Z","expectedReceiveAmount":0.0001024,"isPartner":false}
Please suggest how to get header and data part.
The headers are in $_SERVER. Use $_SERVER['HTTP_X_CHANGENOW_SIGNATURE'] to get the x-changenow-signature header.
The data content is in $postdata. Use
$data = json_decode($postdata);
to convert it to an object. Then you can use $data->status, $data->payinHash, etc. to get the fields of the post data.
I want to post data from an external HTML form to a simple form created in Eloqua, using cURL method. I tried to follow this documentation but I am not able to post data to Eloqua.
When I try from command line (Windows) -
curl --user "usercreds" --header "Content-Type: application/json" --request POST --data "{"testfirstname":"abc","testlastname":"def","singleCheckbox":1}" https://secure.p0{POD Number}.eloqua.com/api/REST/1.0/data/form/{formid}
I get below error:
[{"type":"ObjectValidationError","property":"fieldValues","requirement":{"type":"NoDuplicatesRequirement"},"value":""}]
When I try from PHP, as mentioned here https://www.eehelp.com/question/using-curl-to-repost-to-eloqua-data/
or https://github.com/fredsakr/eloqua-php-request the curl returns HTTP code 0.
This is a simple form created in Eloqua without any validations.
I do not know what I am doing wrong here.
I have a controller in symfony2 that is a post request.
$current_hardware_version = $request->request->get('hardware_version');
I send a curl request in my terminal simulating a call to this
curl --data "hardware_version = 10" http://localhost/app_dev.php/api/hardware_version/00-11-22-33-44-55
yet, I reference the variable in the function and nothing is printed out but "function over" which I coded at the end of the action. Am I not passing the post param properly to this url in curl?
Remove spaces from the parameter quotes:
curl --data "hardware_version=10" http://localhost/app_dev.php/api/hardware_version/00-11-22-33-44-55
I’m trying to post an image and a few nested parameters to an api using django rest framework. I’m trying to set up a curl with -F flags as discussed here with nested params as discussed here:
curl -X POST -S -H 'Accept: application/json' -F "customer[name]=foo&customer[email]=foo#bar.com&customer[zipcode]=1076AL&customer[city]=Amsterdam&customer[address]=foobar" -F "photo=#/Users/vincentvanleeuwen/Desktop/tmp/accord.jpg;type=image/jpg" http://localhost:8000/api/orders/
But I get the following response:
{"customer":{"city":["This field is required."],"email":["This field is required."],"zipcode":["This field is required."],"name":["This field is required."]}}
There seems to be something wrong with my nesting under the -F flag, as the nested variables work if I post it like this:
curl -X POST -S -H "Content-Type: application/json" -d '{"customer":{"name":"Adriaan","email":"adriaan#adriaan.com","zipcode":"1901ZP","address":"caravan","city":"Verweggistan"}}' http://localhost:8000/api/orders/
Any ideas what I’m doing wrong? Any help would be much appreciated!
Try separate -F flags for each parameter? From the curl manual:
Emulate a fill-in form with -F. Let's say you fill in three fields
in a form. One field is a file name which to post, one field is your
name and one field is a file description. We want to post the file
we have written named "cooltext.txt". To let curl do the posting of
this data instead of your favourite browser, you have to read the
HTML source of the form page and find the names of the input fields.
In our example, the input field names are 'file', 'yourname' and
'filedescription'.
curl -F "file=#cooltext.txt" -F "yourname=Daniel" \
-F "filedescription=Cool text file with cool text inside" \
http://www.post.com/postit.cgi
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?