PHP cURL issue, getting http 405 code

I am trying to login to a page using cURL. I am not sure what is wrong but I always get 405 code.
If anyone can take a look and help pls…

$url = "https://app.plooto.com/";
$postinfo = array("email" => "[email protected]", "passphrase" => "passxxx");

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
  "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postinfo));
curl_setopt($ch, CURLOPT_POST, 1);
$html = curl_exec($ch);

$httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
$info = curl_getinfo($ch);

curl_close($ch);

print_r( $info );

Try this instead of your $postinfo option:

curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”);

Thanks for your replay.

I did test, your suggestion and I got 411 error.
Content-length: header which I set and I am back to 405 :slight_smile:

Do you actually need to post to the site or just login with authorization?

I went to app.plooto.com and it is a login screen. So, if you want to do that, meaning, log-in, you can post to the page. But, that is all you can do. You can’t go to another page since there is no cookie info unless you save it yourself. What I mean is that posting to a page normally takes you to another page. You don’t get to the other page if you are only calling the one page. You can use the FOLLOWLOCATION option and it will return the last page once it redirects you after you post to the login page. I would try that first.
CURLOPT_FOLLOWLOCATION, 1L) instead of , 0)

Some sites require use of cookies to get to the second page after logging in. In this case you will need to save the cookie created in the first call and run a second call to get to the page you want to read from. If this “plooto” site is where you get some sort of data to pull from, you must know the actual page you really want to get to. So, a second call to that page using the first page’s cookie would work. I found some explanation of this on StackOverflow’s site. They were talking about page ‘a’ and page ‘b’. ‘b’ being the one with data on it. Here is what was said:

The web site likely uses cookies to store your session information. When you run

curl --user user:pass https://xyz.com/a  #works ok
curl https://xyz.com/b #doesn't work

curl is run twice, in two separate sessions. Thus when the second command runs, the cookies set by the 1st command are not available; it’s just as if you logged in to page a in one browser session, and tried to access page b in a different one.

What you need to do is save the cookies created by the first command:

curl --user user:pass --cookie-jar ./somefile https://xyz.com/a

and then read them back in when running the second:

curl --cookie ./somefile https://xyz.com/b

Alternatively you can try downloading both files in the same command, which I think will use the same cookies.

Not sure if that makes sense to you, but, it really depends on how the “plooto” site is set up.

Hello thank you for detail explanation.
Yes, I need to login then redirect to a page where I can access csv file, that is the goal.
I did not include second URL thinking that my first issue is/was trying to log in.

Actually it is still the issue…

So, you can either save the cookie in part one and use it in part two or combine them into one double-call.
Try either or both and then post back here if you have any other questions. Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service