在symfony connsole中,我的代码看起来像这样:
$client = new Client([
'timeout' => 15,0,
]);
$body =[
"revision" => "1",
"changelog" => "stuff",
"description" => "Testing",
"user" => "Foo bar",
];
var_dump(json_encode($body));
$request = new GuzzleRequest('POST', "https://api.newrelic.com/v2/applications/$appId/deployments.json", array(), ['deployment' => json_encode($body)]);
$response = $client->send($request, ['headers' => ['X-Api-Key' => $apiKey]], ['timeout' => 200]);我得到的回答是:
Invalid resource type: array发布于 2016-12-13 20:32:04
根据this (Guzzle6),您必须指定内容类型,请尝试:
$client = new Client([
'timeout' => 15,0,
]);
$body = [ 'deployment' => [
"revision" => "1",
"changelog" => "stuff",
"description" => "Testing",
"user" => "Foo bar",
]
];
$request = new GuzzleRequest('POST', "https://api.newrelic.com/v2/applications/$appId/deployments.json", ["content-type"=>'application/json'], json_encode($body));
$response = $client->send($request, ['headers' => ['X-Api-Key' => $apiKey]], ['timeout' => 200]);希望这能有所帮助!
发布于 2016-12-13 21:26:47
整理好了:
$body = ['deployment' => [
"revision" => "1",
"changelog" => "stuff",
"description" => "Testing",
"user" => "Foo bar",
]];
$client = new Client([
'timeout' => 15,0,
]);
$request = new GuzzleRequest(
'POST',
"https://api.newrelic.com/v2/applications/$appId/deployments.json",
["content-type" => 'application/json'],
json_encode($body)
);
$response = $client->send($request, ['headers' => ['X-Api-Key' => $apiKey]], ['timeout' => 200]);https://stackoverflow.com/questions/41117158
复制相似问题