curl-library
Re: Logging in from a POST method form
Date: Mon, 25 Feb 2013 23:48:45 +0100
On Mon, Feb 25, 2013 at 01:45:28PM -0500, Donnell Connally wrote:
> I'm having a bit of trouble
> with the curl post option as I'm trying to test login into my account
> on adf.ly. Simply setting CURLOPT_URL to "http://adf.ly/login" and
> the rest of my options works fine and returns the code of the page,
> but if I set CURLOPT_POSTFIELDS, it returns a bad request (400.) If I
> set CURLOPT_POSTFIELDS and then set CURLOPT_POST to 0 (so that it
> should fill in the form but not submit it (correct me if I'm wrong),)
> it returns the correct code of the page, but the form is not filled.
> The fields are url encoded. This is my current code. What could be
> wrong?
A couple of obvious things I see: there are lots parameters missing in the data
you're sending in the code, such as "token" and "bmlUrl"; the site is
sending a cookie that you're not sending back; the data you're sending is
entirely URL encoded, which is probably shouldn't be; and you're doing a GET,
not a POST. Take a look at what a browser sends for the login using something
like the Firefox's LiveHttpHeaders plugin or Chrome's built-in developer tools,
and compare that to a debug log of what your program sends out. You'll quickly
spot differences like this.
> If I
> set CURLOPT_POSTFIELDS and then set CURLOPT_POST to 0 (so that it
> should fill in the form but not submit it (correct me if I'm wrong),)
I'm not even sure what you're saying here. What is "filling in the form" in the
context of a libcurl-using application? An HTML form is a template used by a
browser to send an HTTP request to a remote server. If the user fills in the
form on his screen, the browser will send that data to the serve in the format
specified in the FORM element.
Take a look at http://curl.haxx.se/docs/httpscripting.html for a discussion of
some of the issues at work here.
>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-02-25