Re: How could i do this on CURL?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It ain't easy. I have also read the FAQ of cURL
http://curl.haxx.se/docs/faq.html#Can_I_use_curl_to_send_a_POST_PU

3.18 Can I use curl to send a POST/PUT and not wait for a response?
> No.
> But you could easily write your own program using libcurl to do such
> stunts.
>

Although, i was able to write my own PHP App. I did use PEAR Net_Curl BTW.

<?php
.....

$incomingAId = $_POST['a_id'];
$incomingATrackingId = $_POST['a_tracking_id'];

LogResults("On Access");

// Validate if empty, execute if not
if (!empty($incomingAId) || !empty($incomingATrackingId))
{
    SendResponse();
}
else
{
    Initiate();
}


function Initiate()
{
    // Initiate
    $curl = & new Net_Curl("https://test.example.com/Servlet";);
    $result = $curl->create();

    if (!PEAR::isError($result)) {

        // Set other options here with Net_Curl::setOption()
        $params = "a_id=1234&app_name=cart&a_tracking_id=111";

        $curl->setOption(CURLOPT_COOKIEJAR, "cookieFile.txt");
        $curl->setOption(CURLOPT_POST, 1);
        $curl->setOption(CURLOPT_POSTFIELDS, $params);

        $result = $curl->execute();
        if (!PEAR::isError($result)) {
            //echo $result."\n";
        } else {
            //echo $result->getMessage()."\n";
        }

        $curl->close();
    } else {
        //echo $result->getMessage()."\n";
    }
}

function SendResponse()
{
    LogResults("SendResponse");

    // Initiate
    $curl = & new Net_Curl("https://test.example.com/Servlet";);
    $result = $curl->create();

    if (!PEAR::isError($result)) {

        $xmlSubmission = '<?xml version="1.0"?>';
        $xmlSubmission .= '<collection_request>';
        $xmlSubmission .= '<response_message value="Request" />';
        $xmlSubmission .= '</collection_request>';

        $postedTraffic = "&XML=".$xmlSubmission."";

        $curl->setOption(CURLOPT_RETURNTRANSFER, 1);
        $curl->setOption(CURLOPT_COOKIEFILE, "cookieFile.txt");
        $curl->setOption(CURLOPT_POSTFIELDS, $postedTraffic);

        $result = $curl->execute();
        if (!PEAR::isError($result)) {
            //echo $result."\n";
        } else {
            //echo $result->getMessage()."\n";
        }

        $curl->close();
    } else {
        //echo $result->getMessage()."\n";
    }
}

......
?>

On Feb 6, 2008 9:17 AM, Manuel Lemos <mlemos@xxxxxxx> wrote:

> Hello,
>
> on 02/05/2008 10:34 PM Louie Miranda said the following:
> > I was able to create a working CURL connection and it was great.
> >
> > Although, i have another problem.
> >
> >
> >    1. file: connect - I connect via a CURL to a URL and sends two
> >    parameters (application, just wait and hangs) -- this is intentional
> >    2. file: connect - Receives a reply of the two parameters that i had
> >    just sent
> >    3. file: connect - sends a XML post to the remote url (remote url,
> >    closes the connection and application)
> >
> > Could i send two CURL request in one instance? while waiting?
>
> I am not sure how to do that in a simple way with Curl. The few times I
> have used Curl directly, I used custom HTTP requests instead of other
> options.
>
> Nowadays I use this HTTP client class that wraps the complexity of the
> HTTP protocol and uses preferrably fsockopen to send HTTP requests. Take
> a look the test_http_soap.php example which seems to do something
> similar to what you want:
>
> http://www.phpclasses.org/httpclient
>
>
> --
>
> Regards,
> Manuel Lemos
>
> PHP professionals looking for PHP jobs
> http://www.phpclasses.org/professionals/
>
> PHP Classes - Free ready to use OOP components written in PHP
> http://www.phpclasses.org/
>



-- 
Louie Miranda (lmiranda@xxxxxxxxx)
http://www.axishift.com

Security Is A Series Of Well-Defined Steps
chmod -R 0 / ; and smile :)

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux