Sending file to a php script works fine with curl from terminal but not through advanced rest client or postman.
Curl request-
curl -v --form filename=#/cus-check.json --form name=Upload http://127.0.0.1/cus.php
When sending the same request through ARC or Postman, the $_POST variable in php script returns an empty array.
Images
Related
I have an api to export some information to a csv file. The API is correct and it is downloading my file when I access it from the browser. I need to access this API from the terminal and download the file without having to go to the browser.
My route for the API looks like this:
Route::get('/api/file/export', 'File\FileController#export', [
'middleware'=>'auth.basic'
]);
I tried using curl like this:
curl --user email:password http://example.com/api/file/export
I have tried different curl commands but each of then displays the redirect to login html. When I use -O the command for downloading a file, it downloads a file that has the redirect to login link.
curl --user email:password -O http://example.com/api/file/export
Am I calling the API correctly? How else can I access the API from the terminal?
You should first be logged in your website. You can try this:
curl --user email:password http://domain.tld/login_page
And then use the cookies for your second request:
curl --cookie http://domain.tld/file/to/export
If that is not working, you need to do the whole submit action with cURL, meaning doing POST request with email and password etc.
Someone gave a good solution here
PS: Checkout if you don't need a token to request your API too.
I am creating an API using Laravel and Apache as the backend. My predicament is this, when I type a curl command in my terminal like,
curl -H "API KEY: NIKAPIKEY" --data "param1=value1¶m2=value2" http://localhost:8888/awesome-calendar/public/config
How do I read the header API KEY in my php backend? Like I can read the POST parameters as $_REQUEST.
Answered by #nogad
The function apache_request_headers acts like the var_dump for all HTTP headers
http://php.net/manual/en/function.apache-request-headers.php
I would like to have the following curl request generated using php CURL library for webdav.
curl -n -X MOVE "http://localhost/ocm/remote.php/webdav/dir1/subdir" -H "Destination: http://localhost/ocm/remote.php/webdav/dir1/"
Please help
Go through this..It shows all the curl option available to use in PHP along with examples...
I have a page (realized with a php framework) that add records in a MySQL db in this way:
www.mysite.ext/controller/addRecord.php?id=number
that add a row in a table with the number id passed via post and other informations such as timestamp, etc.
So, I movedo my eintire web applicazione to another domain and all HTTP requests works fine from old to new domain.
Only remaining issue is the curl: I wrote a bash script (under linux) that run curl of this link. Now, obviously it does not works because curl returns an alert message in which I read the page was moved.
Ok, I edited the curl sintax in this way
#! /bin/sh
link="www.myoldsite.ext/controlloer/addRecord.php?id=number"
curl --request -L GET $link
I add -L to follow url in new location but curl returns the error I wrote in this topic title.
It would be easier if I could directly modify the link adding the new domain but I do not have physical access to all devices.
GET is the default request type for curl. And that's not the way to set it.
curl -X GET ...
That is the way to set GET as the method keyword that curl uses.
It should be noted that curl selects which methods to use on its own depending on what action to ask for. -d will do POST, -I will do HEAD and so on. If you use the --request / -X option you can change the method keyword curl selects, but you will not modify curl's behavior. This means that if you for example use -d "data" to do a POST, you can modify the method to a PROPFIND with -X and curl will still think it sends a POST. You can change the normal GET to a POST method by simply adding -X POST in a command line like:
curl -X POST http://example.org/
... but curl will still think and act as if it sent a GET so it won't send any request body etc.
More here: http://curl.haxx.se/docs/httpscripting.html#More_on_changed_methods
Again, that's not necessary. Are you sure the link is correct?
I'm trying to HTTP POST using the following command on linux
curl -X POST --data-ascii "a=hello world" http://www.mysite.com/controller/function_name
Its not working, my server is not accepting the POST at all.
My PHP code is:
<?php
print_r($_POST);
?>
whereas if I try this on my local machine it works.
For ex.
curl -X POST --data-ascii "a=hello world" http://192.168.1.10/controller/function_name
Also, the server is shared host, is it a problem?
What am I doing wrong?