我必须发布一些数据,但相同的地址有一些GET和post功能。我的PHP是发送一个GET而不是一个帖子。
$apiURL = 'https://myAPI.com.br/api';
$data = http_build_query(array('postdata' => 10));
$uriRequest = $apiURL.'/main';
$options = array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
'https' => array(
'header' => 'Content-type: application/x-www-form-urlencoded',
'method' => 'POST',
'content' => $data
),
);
$context = stream_context_create($options);
$result = file_get_contents($uriRequest, false, $context);
if ($result === FALSE) {
return var_dump($result);
}
return var_dump($result);
我知道ssl部分是不安全的,但它只是为了原型的目的。
我不能让PHP发布整数,而不是在附加词'https://myAPI.com.br/api/main‘上发布。
发布于 2018-12-17 13:52:01
从http://php.net/manual/de/function.stream-context-create.php#74795判断,为https
安全页面创建流上下文的正确方法是:
<?php
$context_options = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
);
如您所见,我们使用的是'http' => array...
而不是https
。
https://stackoverflow.com/questions/53816054
复制相似问题