Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP格式化HTTP POST请求中的数据_Php_Http_Formatting_Http Post - Fatal编程技术网

用PHP格式化HTTP 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",

我正在使用一个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",
        "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编码的吗?尝试: