I want to know how write the follwong curl (cmd) command in php curl
annotations.xml is an xml file
curl -v -u admin:geoserver -XPOST -T annotations.xml -H "Content-type: text/xml"
http://localhost:8080/geoserver/rest/workspaces/acme/datastores/nyc/featuretypes
Related
I have a cURL call in a PHP 7.2 script running on CentOS 7 that is passing empty data to an endpoint. In diagnosing the issue, I have tried replicating the issue using cURL on the command-line, and not using the PHP code. Here's the command I am running (I was told to send a Content-Length of 0):
/usr/bin/curl -H "App-Key: 321321321313" -H "App-Token: 321321321312" -H "Content-Length: 0" -H "Accept: application/json" -H "Content-Type: application/json" -d '{"reportCustomFields":[{"label":"THIS","value":"THAT","shown":true},{"label":"UP","value":"DOWN","shown":true}]}' "https://url.here/endpoint_debug.php"
In the endpoint script I am printing the input stream.
$data = file_get_contents('php://input');
print "HEADERS:\n\n";
print_r(apache_request_headers()) . "\n\n";
print "RAW Data:\n\n";
print "'" . $data . "'\n\n";
No matter what I have done, the $data variable is always empty. The result I see is always ''. I also tried sending it to https://webhook.site/ and it, too, shows that the "Form values" are empty.
I have tried with -X POST and without. I tried changing the order of the calls so the URL is before the data (-d) switch. I have tried --data as well.
What could be the issue? I have replicated this on 2 different servers calling the same endpoint. Other code in the same project handles file_get_contents('php://input') properly, so I don't think that's it.
Any guidance would be appreciated!
TLDR: You need to remove -H "Content-Length: 0"
It doesn't make sense why you were instructed to send this if you want a response.
I tried your command unmodified with a webhook.site url, and it can return the content body (for example) without sending the head, and return nothing if sending the header:
Quite simply, this command:
/usr/bin/curl -H "App-Key: 321321321313" -H "App-Token: 321321321312" -H "Accept: application/json" -H "Content-Type: application/json" -d '{"reportCustomFields":[{"label":"THIS","value":"THAT","shown":true},{"label":"UP","value":"DOWN","shown":true}]}' 'https://webhook.site/27f6128e-2f82-4157-99da-99464f22122f'
Returns the body. Whereas this command:
/usr/bin/curl -H "Content-Length: 0" -H "App-Key: 321321321313" -H "App-Token: 321321321312" -H "Accept: application/json" -H "Content-Type: application/json" -d '{"reportCustomFields":[{"label":"THIS","value":"THAT","shown":true},{"label":"UP","value":"DOWN","shown":true}]}' 'https://webhook.site/27f6128e-2f82-4157-99da-99464f22122f'
Obviously returns nothing
The server response headers indicate as much :
> Accept: application/json
> Content-Type: application/json
> Content-Length: 0
>
* upload completely sent off: 112 out of 112 bytes
< HTTP/1.1 200 OK
< Server: nginx/1.14.2
I am trying to use a script to interact with the a website however whenever i send my curl post request, nothing is returned.
curl -X POST --proxy 1.1.1.1:9443 \
-H "Content-Type: application/x-www-form-urlencoded" -d d="google.com" -d n="8.8.8.8" \
-d q="A" http://http://www.kloth.net/services/dig.php
I want to call my upload csv api using curl command but no able to upload file on that which gives me error.
Command I am using as follow:
curl -i -X POST -H "Content-Type:application/json" https://api.staging.mailzap.com/api/v1/api-key/upload-csv -d '{"apiKey":"Srkk8RL8xETAeJ0lTm85","email_csv":'#\"C:/Users/viral.champanery/Desktop/publicapi/test.txt\"',"team_id":282}'
following option also not working
curl -i -X POST -H "Content-Type:multipart/form-data;application/json;application/csv;" https://api.staging.mailzap.com/api/v1/api-key/upload-csv -d '{"apiKey":"Srkk8RL8xETAeJ0lTm85","email_csv":"C:/Users/viral.champanery/Desktop/publicapi/test.txt","team_id":282}'
also not working following
curl -i -X POST -H "Content-Type:multipart/form-data;application/json;application/csv;" https://api.staging.mailzap.com/api/v1/api-key/upload-csv -d '{"apiKey":"Srkk8RL8xETAeJ0lTm85","team_id":282}' -F "email_csv=#/C/Users/viral.champanery/Desktop/publicapi/test.csv"
email_csv=#/C/Users/viral.champanery/Desktop/publicapi/test.csv"
help me to upload file with json other parameter in api using curl command
I have been working with Jenkins, and now Im stuck when I try to make an HTTP Post using curl, I am sending a json file, to a file in my page who is waiting for it, and then do some functions, the code I am using is the following:
curl -X POST -k -i -H "Accept: application/json" -w "%{body}" -w "%{http_code}" -d "#/var/lib/jenkins/workspace/myFolder/session.json" http://mypage.com/myFolder/newfile.php
But apparently Im not sending correctly the data of the file, the newfile.php has something like this:
echo $_REQUEST['sessionId'];
But always get an error when I try to echo the index sessionId, I mean my file "newfile.php" is not getting anything from my jenkins curl, can you help me out?
Thanks in advance!!
The JSON that you send is in the request body. The keys/values will not be available in the $_REQUEST array, hence why you are getting the error. You will need to access the request body in order to get the sessionId property.
$requestBody = file_get_contents('php://input');
$session = json_decode($requestBody);
$sesionId = $session["sessionId"];
echo "Session ID: $sessionId";
The file_get_contents('php://input') returns the body of the POST request.
Make sure to also add the appropriate Content-Type header to your post request:
curl -X POST -k -i -H "Accept: application/json" -H "Content-Type: application/json" -w "%{body}" -w "%{http_code}" -d "#/var/lib/jenkins/workspace/myFolder/session.json" http://mypage.com/myFolder/newfile.php`
what is curl -u equivalent in php unirest
Blockscore API:
$ curl https://api.blockscore.com/people \
-u sk_test_n5049aa6053c9a0217bea78070fbf501: \
--header "Accept: application/vnd.blockscore+json;version=4"
Api key: sk_test_n5049aa6053c9a0217bea78070fbf501
I want to try this out in Unirest. but what is -u?
is it a header or a post?
The -u flag for cURL is used to set the credentials for HTTP Basic authentication. The provided credentials will be base64-encoded and presented in the "Authorization" header as in:
Authorization: Basic c2tfdGVzdF9uNTA0OWFhNjA1M2M5YTAyMTdiZWE3ODA3MGZiZjUwMTo=
So it is a header.
In unirest you should be able to use:
Unirest\Request::auth('sk_test_n5049aa6053c9a0217bea78070fbf501', '');