0
ググルに新しい。私はそれを使用してRESTエンドポイントに連絡しようとしています。 curl経由でリクエストを送信するか、chromeのpostman appのようなものを使用して、期待されるJSONレスポンスを返します。以下のguzzleを使って送信すると、ヘッダーが埋め込まれていないURLにヒットした場合に返されるものと同様の404エラーが返されます。要求にデフォルトのヘッダーが適用されない
なぜこの要求にヘッダーが含まれないのですか?
// Get extra detail for the object
$client = new \GuzzleHttp\Client([
'base_uri' => env('OPENIDM_URL'),
'headers' => [
'Content-Type' => 'application/json',
'X-OpenIDM-Username' => env('OPENIDM_USER'),
'X-OpenIDM-Password' => env('OPENIDM_PASS'),
'Authorization' => 'Basic Og=='
]
]);
$request = new \GuzzleHttp\Psr7\Request('GET', $attributes['sourceobjectid']);
$res = $client->send($request);
私はクライアントの内容と要求オブジェクトをダンプしました。彼らは次のように見えます:
Client {#181 ▼
-config: array:8 [▼
"base_uri" => Uri {#188 ▼
-scheme: "https"
-userInfo: ""
-host: "my.url.here.com"
-port: null
-path: "/openidm"
-query: ""
-fragment: ""
}
"headers" => array:5 [▼
"Content-Type" => "application/json"
"X-OpenIDM-Username" => "myuser"
"X-OpenIDM-Password" => "mypass"
"Authorization" => "Basic Og=="
"User-Agent" => "GuzzleHttp/6.2.1 curl/7.38.0 PHP/5.6.26-0+deb8u1"
]
"handler" => HandlerStack {#169 ▶}
"allow_redirects" => array:5 [▶]
"http_errors" => true
"decode_content" => true
"verify" => true
"cookies" => false
]
}
Request {#189 ▼
-method: "GET"
-requestTarget: null
-uri: Uri {#190 ▼
-scheme: ""
-userInfo: ""
-host: ""
-port: null
-path: "managed/user/eb758aab-7896-4196-8989-ba7f97a7e962"
-query: ""
-fragment: ""
}
-headers: []
-headerNames: []
-protocol: "1.1"
-stream: null
どのような提案も大歓迎です。
HandlerStackを使用して行うことができます。 Guzzleのドキュメントをご覧ください - http://docs.guzzlephp.org/ja/latest/handlers-and-middleware.html#handlerstack – mrDinkelman