post - cURL to Guzzle conversion -
i have curl works well:
curl -h "authorization: token 71e24088d13304cc11f5a0fa93f2a2356fc43f41" -h "content-type: application/json" -x post -d '{ "reviewer": {"name": "test name", "email": "test@email.com"}, "publication": {"title": "test title", "doi": "xxx"}, "complete_date": {"month": 6, "year": 2015} }' https://my.url.com/ --insecure
and use multi curl symfony2 guzzle
what tried far:
$client = new \guzzle\http\client(); $request = $client->post('https://my.url.com/'); $jsonbody = "'{ "; $jsonbody .= '"reviewer": {"name": "'.$review['name'].'", "email":"'.$review['email'].'"}, '; $jsonbody .= '"publication": {"title": "'; if ($review['article_title'] != '') $jsonbody .= $review['article_title']; else $toexec .= $review['manuscript_title']; if ($review['doi'] != '') $jsonbody .= '", "doi": "'.$review['doi'].'"}, '; else $toexec .= '"}, '; $jsonbody .= '"complete_date": {"month": '.$month.', "year": '.$year.'}'; $jsonbody .= "}' "; $options = [ 'headers' => [ 'content-type' => 'application/json', 'authorization' => 'token 71e24088d13304cc11f5a0fa93f2a2356fc43f41' ], 'body' => $jsonbody, ]; $request->getcurloptions()->set(curlopt_ssl_verifyhost, false); $request->getcurloptions()->set(curlopt_ssl_verifypeer, false); $response = $client->post('-d', $options);
but doesn't work, getting array result not supposed to.
you might try moving authorization curl.
$token = '71e24088d13304cc11f5a0fa93f2a2356fc43f41'; $request->getcurloptions()->set(curlopt_httpauth, curlauth_basic); $request->getcurloptions()->set(curlopt_userpwd, "$token:x");
x password there none needed add x (random character)
Comments
Post a Comment