用PHP格式化HTTP POST请求中的数据
我正在使用一个API,它给出了一个示例,说明他们希望如何格式化我即将发出的POST请求的数据。这是他们的例子:用PHP格式化HTTP POST请求中的数据,php,http,formatting,http-post,Php,Http,Formatting,Http Post,我正在使用一个API,它给出了一个示例,说明他们希望如何格式化我即将发出的POST请求的数据。这是他们的例子: un=chris& key=xxxx& origin=plot& platform=lisp& args=[[0, 1, 2], [3, 4, 5], [1, 2, 3], [6, 6, 5]]& kwargs={"filename": "plot from api", "fileopt": "overwrite",
un=chris&
key=xxxx&
origin=plot&
platform=lisp&
args=[[0, 1, 2], [3, 4, 5], [1, 2, 3], [6, 6, 5]]&
kwargs={"filename": "plot from api",
"fileopt": "overwrite",
"style": {
"type": "bar"
},
"traces": [1],
"layout": {
"title": "experimental data"
},
"world_readable": true
}
我对如何将PHP中现有数组中的这些数据组合在一起感到困惑。从我的理解来看,这个例子显示了一个编码字符串,它只是部分编码的?到目前为止,我通过从数组中提取键和值,自己将字符串组合在一起。
我正在寻找一种更简洁的方法来使用现有方法实现这一点?我相信使用http\u build\u查询将为您解决这一问题。 举个例子,下面是如何使用它的示例:
$args = array(array(0,1,2), array(3,4,5), array(1,2,3), array(6,6,5));
$kwargs = array(
'filename' => 'plot from api',
'fileopt' => 'overwrite'
'style' => array('type' => 'bar'),
'traces' => array(1),
'layout' => array('title' => 'experimental data'),
'word_readable' => true
);
$request = array(
'un' => 'chris',
'key' => 'xxx',
'origin' => 'plot',
'platform' => 'lisp',
'args' => $args,
'kwargs' => $kwargs
);
$queryString = http_build_query($request);
echo $queryString;
更多信息:你能发布你的代码吗?kwargs是JSON编码的吗?尝试: