简体   繁体   中英

Posting in a form using CURL PHP

this is the form:

<textarea name="message" id="messageContent" rows="18" wrap="virtual" tabindex="2"></textarea>

    <span id="formSubmit">
<a href="#" class="formSubmit" tabindex="3">
<img src="/clear.gif" class="master-sprite sprite-pm-send">
</a>
    </span>

the formSubmit class is an Ajax function I tracked down on the source code, I used Fiddler to capture the params I needed to POST and found this:

callCount=1
c0-scriptName=PostFunctions
c0-methodName=insertPost
c0-id=1894_1310435282892
c0-param0=number:1578007
c0-param1=string:Hello%20World!
xml=true

Hello World, was what I wrote on the textarea and posted, fiddler also found a cookie on header. not sure if I need to use it? Can someone help, I'm trying to post that for 2 days now, this is really making me crazy ! thanks

request the page and split the cookie in http headers response Example:

//get the cookies 
$ch = curl_init("url"); 
$opts = array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER => true
            ); 

curl_setopt_array($ch, $opts); 
$res = curl_exec($ch); 
preg_match_all("/set-cookie:\s*([^\n]+)/i",$res,$cookies); 
$cookies = implode(";", $cookies[1]); 

//send the post with cookies in headers 
$ch = curl_init("url"); 
$opts = array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER => true,
        CUOROPT_COOKIE => $cookies, 
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $params
            ); 

curl_setopt_array($ch, $opts); 
$res = curl_exec($ch); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM