How to use argv with file_get_contents or cURL or something similar

Viewed 69

I want to pass parameters with cURL or file_get_contents and get it using argv

Using cURL

curl -X POST -H "Content-Type: application/json" -d '{"param1": "MY DATA"}' 'http://[serverIP]/file.php'

using file_get_contents

<?php

$url = 'http://[serverIP]/file.php';
$data = array('param1' => 'MY DATA');

$options = array('http' => array(
    'method'  => 'POST',
    'content' => http_build_query($data)
));

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

print_r($result);

and I want this data as an argument - like it should print an array of arguments like

Array
(
    [0] => directory/file.php
    [1] => MY DATA
)

Please Note that I can use POST/GET method for getting the data but I want to know can I use argv when using curl command or anything else similar?

0 Answers
Related