Getting an example POST stream created by Curl to support porting to C #

I have the task of converting the following block of PHP code to execute multi-page HTTP mail. I understand the basics of executing HTTP messages (my code is already reporting some JSON), and I read about the basic principles of multidisciplinary requests. However, Curl obviously does a lot of work on its feet behind the scenes, which needs to be converted to a .NET stream entry. However, with these things, the devil is in the details.

Not familiar with Curl and be a newbie to PHP, is there a way, using the code, to see a request that is finally sent with curl_exec? A real life example will really help. In fact, I'm fine with simple fields - each of which has a separate border / part. This is a JPEG image encoding, which is complicated for me. Could I set up the PHP environment and somehow debug it? I conclude that Curl is a kind of web client, i.e. It does a lot of what a web browser does without a user interface.

<?php

    function AddPhoto( $account, $password, $pubId, $photoId, $owner, $pubDate, $attribution, $caption, $keywords, $photoPath )
    {
        // set up the arguments of the multipart form data
        $args = array( 'Method' => 'AddPhoto', 'Account' => 'Test', 'Password' => 'pw', 

                      'PubID' => 'WOR/1002',
                      'PhotoID' => '12345',
                      'Owner' => 'me',
                      'PubDate' => '2015-07-01',
                      'Attribution' => '',
                      'Caption' => 'the front door',
                      'Keywords' => 'Pub',

                      'Photo' => new CurlFile( $photoPath,              // path to the file
                                                'image/jpeg',               // MIME type of the file
                                                'image'                     // file name (not used)
                                             )
                    );

        // create a curl request object
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, 'http://dev.camrapubs.org.uk/simon/PubDatabase/API2.php');
        curl_setopt( $ch, CURLOPT_POST, 1 );                // use the POST method
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $args );      // supply the arguments for the POST
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );      // ensure curl_exec returns the result rather than echoing it

        // make the call and get the result
       return curl_exec($ch);
    }

    $result = AddPhoto( ‘xx', ‘xx', 'WOR/1002', '12345', 'me', '2015-07-01', 'copyleft', 'The front door', 'Pub', 'sample.jpg' );
    echo 'result = ', $result, PHP_EOL;
?>
+4
source share
2 answers

Rob

Perhaps you should look at this?

Php - Debug Twisting

Best wishes for success :-)

+1
source

, Curl, .

, , verbose Curl , , , .

. Wireshark , Charles Proxy. , - HTTP-.

CURL , - Charles, :

curl_setopt( $ch, CURLOPT_PROXY, "127.0.0.1:8888");

, Charles.

. POST .

0

Source: https://habr.com/ru/post/1606660/


All Articles