我有命令:
curl -k -u **username:password** --request POST -H "Content-Type:application/json" -d "{\"name\":\"John\",\"age\":\"31\",\"test\":\"New York\"}" http://siteteste.com/receive.php
我想用PHP获取服务器端的用户名和密码。我正在使用 POST 方法。
我的PHP:
<?php
// Only allow POST requests
***// I want the username and password here with PHP POST.***
***$user = $_POST[""]; // Not working :(***
if (strtoupper($_SERVER['REQUEST_METHOD']) != 'POST') {
throw new Exception('Only POST requests are allowed');
}
// Make sure Content-Type is application/json
$content_type = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '';
if (stripos($content_type, 'application/json') === false) {
throw new Exception('Content-Type must be application/json');
}
// Read the input stream
$body = file_get_contents("php://input");
// Decode the JSON object
$object = json_decode($body, true);
// Throw an exception if decoding failed
if (!is_array($object)) {
throw new Exception('Failed to decode JSON object');
}
// Display the object
$getit = $object['test'];
print $getit;
我该怎么做?
我尝试了,但没有成功。
我搜索 StackOverflow 和其他网站,但没有找到信息
幕布斯7119047