PHP cURL with XmlHttpRequest
The scenario: There's this voting form (vote.php) with 3 fields where one is a hidden field containing a hash. Once you submit the form, it requests using GET to a separate script (process.php) via XHR. I am trying to simulate this via cURL but only gotten so far to getting the hash and preserving the phpsessionid using a cookie jar.
The problem: The processing script (process.php) seems to be able to detect if a request didn't push thru using XHR and will return an error if I just submit its required parameters using regular cURL GET.
So how do I sim开发者_开发技巧ulate XHR in cURL? Or I may be even wrong in saying there's XHR in cURL so can you please advice any methods on how to achieve this.
There is a good chance that process.php checks for an XHR request by looking at the HTTP_X_REQUESTED_WITH header, for example:
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest") { /* Do stuff here */ }
So you could try setting that header in your cUrl request:
curl -H "HTTP_X_REQUESTED_WITH:XMLHttpRequest"
That has a good chance of working. Good luck!
Add the following header: X-Requested-Width: XMLHttpRequest
. This is added by all major JS libraries to ease identifying such requests on the server.
精彩评论