php - Guzzle send empty array in multipart request -
i using guzzle 6 send multipart form request 3rd party api(cloud foundry). api takes 2 parameters "resources" , "application". here doc call making. in short deploys binary an applications server. below code using in guzzle. getting "invalid resource type" error when trying send empty array contents of "resource" parameter. guzzle seems allow strings here? api requires empty array sent when new binary being pushed.
here code:
$response = $this->client->put($this->baseurl . "apps/7887990-654e-4516-8ce9-b37bc2f93a87/bits", [ 'multipart' => [ [ 'name' => 'resources', 'contents' => [] ], [ 'name' => 'application', 'contents' => '@/tmp/cfdownloadyqfop7', ] ] ]);
the above fails mentioned error, , changing ti string results in bad request api.
here curl command works properly:
curl -k -x put -h "authorization:token here" -f 'resources=[]' -f "application=@/tmp/cfdownloadf9axle" https://api.cloudfoundry.com/v2/apps/2d0f491b-d8dd-4b3a-96f9-58b3678e5dad/bits
does know how work using above guzzle code?
i have solved issue. turns out not matter of sending array, error being thrown guzzle masking real issue.
first set guzzle debug, , turned off exceptions(see below). guzzle mask actual exceptions third party if not off. getting 400 bad response correct hiding actual message file trying send not able unzipped. decided change multipart request use 'fopen' option guzzle docs, rather using '@' cloudfoundry docs. solved problem , working fine now. see belwo updated request.
new client(['debug'=>true,'exceptions'=>false,'headers' => ['authorization' => "bearer " . $token, "accept" => "application/json"], 'verify' => false])
guzzle request:
$response = $this->client->put($this->baseurl . "apps/cb44bb975-654e-4516-8ce9-b37bc2f93a87/bits", [ 'multipart' => [ [ 'name' => 'resources', 'contents' => '[]' ], [ 'name' => 'application', 'contents' => fopen('/tmp/cfdownloadyqfop7', 'r') ] ] ]);
Comments
Post a Comment