cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: asynchronous posting to a webpage with cURL

From: Ralph Mitchell <ralphmitchell_at_gmail.com>
Date: Mon, 27 Aug 2007 09:28:30 -0500

On 8/27/07, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Sun, 26 Aug 2007, Znigniew Widomski wrote:
>
> > Also 1 final question. On the 10th post, the server returns back xml data as
> > normal. The client side ajax then interprets this xml data and runs a
> > special javascript function which causes the page to automatically POST
> > again on its own to another url and then be redirected. I know that curl can
> > follow redirects, but what is happening is that another post is being posted
> > and then thus redirected. so it would be curl posting, curl posting, with
> > the second as part of default behavior of the remote site. Is that possible
> > with cURL that it can follow another post?
>
> I don't understand this question. When a POST is sent, the response to that
> request can contain a redirection sure. And if libcurl is told to follow
> locations, it will do so. The actual HTTP response code number (3xx) in the
> response will then tell libcurl if it should do the next request as a GET or
> as another POST.

It appears that the client-side Ajax and/or javascript may be doing one of:

  1) "top.location=newurl", or maybe "window.location=newurl". I
think I've also seen "window.href=newurl", or something similar.

  2) executing "document.form.submit", possibly after filling in form
variables for itself from stuff it had laying around.

Curl does not even attempt to interpret plain javascript, let alone
whatever complexities Ajax adds to the page. The curl scripter needs
to trace the path the browser takes through all the bits and pieces in
order to reconstruct the post. I've been faced with this a couple of
times, and though it irritates me beyond belief, I've generally had to
ignore whatever fancy stuff was in the page, and go with a hardwired
solution. I.e., us LiveHTTPHeaders to see what the browser spits out
after the fancy ajax stuff, and then duplicate that.

Ralph Mitchell
Received on 2007-08-27