php - 使用 file_get_contents 发布 json
问题描述
在尝试创建脚本之前,我首先尝试使用邮递员应用程序,一切顺利,没有任何限制,但是在我使用我制作的脚本后,结果与应用程序邮递员给出的不一样。
这是邮递员应用程序的结果
这是从邮递员那里获得的输出结果
然后,我尝试使用我创建的脚本,如下所示
<?php
$postdata = http_build_query(
array (
'question' => 'this is questions',
'questionMedia' => '',
'choices' =>
array (
0 =>
array (
'text' => '123123123',
),
1 =>
array (
'text' => 'qweqweqwe',
),
2 =>
array (
'text' => 'asdasdasd',
),
3 =>
array (
'text' => 'zxczxczxcxc',
),
),
'allowMultiChoice' => false,
'endDate' => NULL,
'enableCaptcha' => false,
'hideResults' => false,
'restriction' => 'ip',
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'content' => $postdata,
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36\r\n'
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://www.polltab.com/api/poll/create', false, $context);
echo $result;
?>
但是,从上面的脚本中,会产生如下所示的输出。
这是从脚本获得的输出结果
解决方案
推荐阅读
- liferay - Liferay 6.2 到 7.1.1 的迁移
- docker - Docker-Compose 入口点/命令
- java - 使用 for 循环的 Java 阶乘代码未显示准确的输出
- r - 为什么切片函数在不明确使用 dplyr 的情况下不起作用
- sql-server - SQL Server 转到光标所在的下一行
- css - ReactJS:标签无法从远程 url 加载图像并转换提供的 url 失败并出现 404
- c# - 确定虚拟键代码是否属于 .NET 中的扩展键或修饰键
- nservicebus - nservicebus 多端点配置
- vb.net - 如何使打开的图形链接与 301 重定向一起使用
- c++ - 无法在 Qt (C++) 中调用 PaintEvent