|
Posted by Christoph Burschka on 07/12/07 12:54
Grey Alien schrieb:
> Apologies for the cross post. I am quite desperate and do not know which
> ng would be the most appropriate.
>
> I am trying to programatically POST an ASP form, to allow me to log on
> to a site programatically.
>
> <form name="aspnetForm" method="post" action="Default.aspx"
> id="aspnetForm">
> <input name="_ct99:Content:UsrName" type="text"
> id="_ct99_Content_UsrName" />
> <input name="_ct99:Content:Pwd" type="password"
> id="_ct99_Content_Pwd" />
> <input type="submit" name="_ct99:Content:btnLogon" value="Logon"
> id="_ct99_Content_btnLogon" />
> <input id="_ct99_Content_SavePwd" type="checkbox"
> name="_ct99:Content:SavePwd" /></p>
> </form>
>
>
> Could anyone please specify the data I should pass with the
> CURLOPT_POSTFIELDS flag option (i.e. passed to curl_easy_setopt()) ?
> I have not been succesful so far in trying to log on.
I can't help with cURL, as I got stuck on similar problems when I tried
using it. Now I just construct the HTTP request myself and use
fsockopen() to transmit it - I don't know why, but it was faster than
cURL on my server...
POST query data is constructed as follows:
foreach($form_fields as $name=>$value) {
$post[] = urlencode($name) ."=". urlencode($value);
}
$post = implode("&",$post);
You can then submit the data like this:
$stream = fsockopen($hostname, 80);
fwrite($stream, "POST /action/url HTTP/1.1\n");
fwrite($stream, "Host: $hostname\n");
fwrite($stream, "Content-Length: ". strlen($post) ."\n\n");
fwrite($stream, $data ."\n");
while (!feof($stream) && $chunk = fread($stream, 1024)) {
$response .= $chunk;
}
fclose($stream);
Look at the content of $response to find out what you need to do next -
you probably want to get the "Set-Cookie" header that contains the login
session cookie, and use it in later requests to tell the server you're
logged in.
--
cb
[Back to original message]
|