1

I want to convert this linux command console to PHP code, to send data via curl,

curl -X POST -d 'data[][street]=1' link.....

Thanks!!

3 Answers 3

2
$fields = 2;
$fields_as_string = "key=value&key2=value"    

//open the curl connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
// set the number of post fields
curl_setopt($ch,CURLOPT_POST, $fields);
// set the fields
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_as_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

Don't forget to make sure you've enabled the curl php extension.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use PHP cURL Library.

    <?php
    //initializing the connection.
    $connection = curl_init();

    curl_setopt($connection, CURLOPT_URL,"http://www.yoursite.com");
    curl_setopt($connection, CURLOPT_POST, 1);
    curl_setopt($connection, CURLOPT_POSTFIELDS,http_build_query(array('postvar1' => 'value1')));

    // receive server response ...
    curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);

    $server_output = curl_exec ($connection);

    curl_close ($connection);

    ?>

Comments

0

Have you tried PHP cURL library? ;)

https://php.net/curl

PHP documentation always gives nice examples.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.