I'm trying to get CURL to work with a Wordpress installation that requires a user to be logged in to see the content. I've exported the cookies from my logged in session and saved them in a cookie jar file. When I run curl, I just get redirected to a login screen. Any idea why?
The command I am running is:
curl --cookie cookie_jar.txt -L <url>
You should make two requests, as the cookie in the cookie jar file that verifies authentication may become stale/expire. The first request should be to the script that handles authentication, which will be the action script that the login page's form sends the POST request with necessary authentication variables.
curl --cookie cookie_jar.txt --data "username=someguy&press=mahpass" -L http://mywordpressblog.com/login.php
Now, any subsequent requests using the same cookie jar will send the cookies already in the cookie jar that match the cookie domain:
curl --cookie cookie_jar.txt -L http://mywordpressblog.com/page-i-wanted-all-along.php
Related
so I am building an API in Laravel and I created custom middleware to authenticate the user based on their username and password either as part of authorization header or by passing the credentials in as part of the query string.
Example:
curl http://myapi.com/api/v1/getsomething -u username:password
-- or --
curl http://myapi.com/api/v1/getsomething?username=username&password=password
Both methods worh in the browser as expected, but when I try and run these via curl in the terminal, my middleware is not being hit during the request. Is there any reason why this may be?
I am trying to access the following URL using cURL:
http://bizsearch.penrithcity.nsw.gov.au/eplanning/Pages/XC.Track/SearchApplication.aspx
However, when I attempt to access the web page I am redirected to:
http://bizsearch.penrithcity.nsw.gov.au/eplanning/Common/Common/terms.aspx
I tried utilizing the following cURL command to get passed this:
curl --cookie-jar "CookieTest.txt" url(common terms) -d "ctl00$ctMain1$chkAgree$chk1=on&ctl00$ctMain1$BtnAgree=I Agree"
curl --cookie "CookieTest.txt" url(search application)
Any help would be greatly appreciated as I am new to cURL and am having difficulty troubleshooting. I am wanting to pull the XML from the search application page.
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'm trying to script bash to do a few simple curl commands.
I can generate a cookie that I want to use with the following command:
curl -c cookie --data "user=user&password=pass" //example/login.php
However, when I try passing it into the site again the cookie is ignored. It's as if I didn't even login into the first place. The command I'm using is the following:
curl -b cookie //example/
What am I doing wrong?
Any help would be appreciated thanks.
it turns out I wasn't generating my cookie correctly after all.
I was actually missing some additional variables that were required in my POST statement, which interacted with the php log in script I was using.
You may want to store the cookie that comes back. You do so by specifying a cookie file:
curl -c cookies.txt -d "user=user&password=pass" //example/login.php
and to use those cookie in later requests you do:
curl -b cookies.txt //example/
as my client needs, I developed a code to login via cURl.
login to www.web1.com and store cookies in cookie.txt
go to www.web2.com and browse a page using that cookie.txt
no problem with www.web2.com
so when i want to do this with www.web3.com, the problem appears.
the www.web3.com uses session and cookies itself and I have to gather and use them.
it means I should have tow series of cookies, first those from www.web1.com , and second those from www.web3.com , then request the www.web3.com/somepage
how I can do that?
You can execute a command line call to curl from php to save cookies to a file like so:
curl -c '/tmp/mycookies.txt' 'http://www.site.com/login.php
Then use those cookies when submiting to the page like so:
curl -b '/tmp/mycookies.txt' -d 'uname=MyLoginName&pass=MyPassword&action=login&x=67&y=11' 'http://www.site.com/login.php'
For more info about these command line flags:
http://curl.haxx.se/docs/manpage.html
You can user the following line to get the cookie informations:
curl -k -s -d'user=foo&pass=bar' -D- https://server1.com/login/ -o/dev/null -f
Use shell_exec or exec to run this command. After getting the header information you can parse the cookie information. Use a helper class or write your own parser -> http://framework.zend.com/manual/en/zend.http.cookies.html (Zend_Http_Cookie::fromString)
You can store this information in a session and not in a text file. For web3.com grab also the cookie information and save it in the session or the cookie.txt file.