Reputation: 315
New to guzzle. I am trying to use it contact a REST endpoint. Sending the request via curl or using something like postman app for chrome it returns the expected JSON response. Sending it using guzzle below is returning a 404 error similar to what would be returned if I hit the URL without the headers inlcuded.
Why are the headers not making it into this request?
// 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);
I have dumped the content of the client and request objects. They look as follows:
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
Any suggestions would be much appreciated.
Upvotes: 1
Views: 894
Reputation: 1042
If you construct the request object yourself, Guzzle won't apply configurations to it.
You either have to use the convenience HTTP methods (get, put, etc) called from the client or use a custom middleware.
The first one is easier, the second one gives you more power, but responsibility too.
Upvotes: 1