【发布时间】:2017-10-11 07:54:08
【问题描述】:
我正在尝试使用 Guzzle 发布多部分和 json 数据,以使用 Phonegap Build API 构建我的应用程序。我已经尝试了很多调整,但仍然得到错误结果。这是我正在使用的最新功能:
public function testBuild(Request $request)
{
$zip_path = storage_path('zip/testing.zip');
$upload = $this->client->request('POST', 'apps',
['json' =>
['data' => array(
'title' => $request->title,
'create_method' => 'file',
'share' => 'true',
'private' => 'false',
)],
'multipart' =>
['name' => 'file',
'contents' => fopen($zip_path, 'r')
]
]);
$result = $upload->getBody();
return $result;
}
这是我从 API 获得成功结果的正确 curl 格式,但我的桌面上有文件:
curl -F file=@/Users/dedenbangkit/Desktop/testing.zip
-u email@email.com
-F 'data={"title":"API V1 App","version":"0.1.0","create_method":"file"}'
https://build.phonegap.com/api/v1/apps
【问题讨论】:
-
This option cannot be used with body, form_params, or json来自docs.guzzlephp.org/en/latest/request-options.html#multipart -
那你有什么建议?我应该将此帖子恢复为正常的 CURL 帖子吗?
-
您可以执行 2 个请求,或者将其编码到 url 中
标签: laravel phonegap-build guzzle