3
次のコードを使用して、別のシステムからAPIを使用してコンテンツを保存しています。資格情報を追加しましたが、間違った資格情報エラーが表示されます。それは郵便配達員に完全に働いています。Guzzle PUTリクエスト認証エラー
$client = new GuzzleHttpClient();
try {
$request = new \GuzzleHttp\Psr7\Request('PUT', config('cms.api.backend') .'/products/'. $nid,
[
'auth' => [config('cms.api.user'), config('cms.api.password')],
'form_params' => [
'copywrite' => Input::get('copywrite'),
'status' => $status
],
]);
$promise = $client->sendAsync($request)->then(function ($response) {});
$promise->wait();
}
catch (RequestException $e) {
$this->logHttpError($e->getResponse()->getStatusCode(), $e->getResponse()->getBody(true));
}
上記のコードで何が間違っている可能性がありますか?
以下は、郵便配達員の輸出コードです。 \GuzzleHttp\Psr7\Request
で
$request = new HttpRequest();
$request->setUrl('http://mybackend/api/products/74371');
$request->setMethod(HTTP_METH_PUT);
$request->setHeaders(array(
'postman-token' => 'e0ddcaea-4787-b2c5-0c52-9aaee860ceac',
'cache-control' => 'no-cache',
'authorization' => 'Basic authenticationcode',
'content-type' => 'application/x-www-form-urlencoded'
));
$request->setContentType('application/x-www-form-urlencoded');
$request->setPostFields(array(
'copywrite' => 'date to be saved'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
あなたは例のリクエストをお見せでした:それはそれらを認識し、
form_params
オプションがContent-Type: application/x-www-form-urlencoded
ヘッダとして解析され、あなたの要求のための有効なストリームを作成します(あなたが要求コンストラクタで直接それをしたい場合には、http_build_query()
機能を使用しています)郵便配達員と一緒に送信されました(正確なデータは必要ありません)? – shudder@振込先 - 質問に追加して、ご確認ください – Unnikrishnan