cURL / Mailing Lists / curl-library / Single Mail


Re: asynchronous posting to a webpage with cURL

From: Znigniew Widomski <>
Date: Sun, 26 Aug 2007 07:35:31 -0700 (PDT)

  Znigniew Widomski wrote:

> I'm using the cURL library built in with php 5. I'm trying to use curl
> to POST to a website that uses ajax an asynchronous posting to
> actually "post" things. I'm just completely and utterly confused when
> you mix words like asynchronous, ajax, and curl together. I understand
> how to post querystrings with curl, this is quite simple to me.
> Asynchronously posting a series of posts to 1 website I am lost...
> Could someone help un confuse me on this... or simply expand if
> asynchronous posting via ajax that a website may inhibit, if this
> limits me in any way with cURL and if so how??

Don't get caught up too much on the asynchronous part. This just means
that the request is initiated in the browser in the background, at some
point after the page has completed loading, without causing a new page
to load. But from the standpoint of HTTP, it is no different than any
other GET or POST. And curl is not a browser at all, it is simply a way
to initiate one or more GET or POSTs, so the notion of "inside a page"
or "after the page has loaded" doesn't really apply at all.

You do the same you do with any other use of curl -- figure out the
location of the GET/POST and the various parameters, and away you go.
You'll have to use e.g. Firebug or LiveHTTPHeaders or Wireshark most
likely because the location and parameters won't be obvious just from
inspection, so you'll need to observe what the scripting does and then
replicate that.

What you may run into though is that the result of this request is some
kind of abstract data -- XML, JSON, whatever. The code to take that
data and cause it to modify the appearance of the page is part of the
scripting that runs in the browser, and that is completely out of the
domain of curl, so if you are expecting HTML you may be disappointed.


mazon26's latest reply:
  Hey Brian!
  Wow! You are right on the money. I did indeed do some testing with wireshark and live http headers. What is going on is a series of 11 posts to the page to culminate in the final process of the remote page i'm accessing. I've analyzed all this with wireshark. With each post request the server returns the HTTP/XML protocol, and sends back some xml that the clientside ajax then interprets. It is vital that I be able to catch and read this xml that the server sends back to the client. With wireshark, I can easily read it. I don't know if this is what you meant before, but reading this XML with curl is something I definitely want to do. Is it possible to return this xml data with curl? All I know is that it is not an HTTP protocol but the http/xml protocol according to wireshark. Is the xml data part of the header? But it is returned via the http/xml protocol and curl I think only returns the http protocol. Anyways, if not possible with curl maybe there is some other http
 access library you'd recommend to use with php? (soap, pecl)
  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?
  Thanks for you help Brian! (and others)

Shape Yahoo! in your own image. Join our Network Research Panel today!
Received on 2007-08-26