Php + guzzle sending authorization key in title

I am new to Guzzle and I am trying to create the following REST call:

https://product-search.api.cj.com/v2/product-search?website-id=1594990&keywords=%2Bsony+-camera

GET /v2/product-search?website-id=1594990&keywords=%2Bsony+-camera HTTP/1.1
Host: link-search.api.cj.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: __utma=128446558.2099392322683464700.1239639722.1239639722.1239927095.2; __utmz=128446558.1239639722.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); CONTID=8073; cjuMember=0; JSESSIONID=aM5RSWdqdd_5
Authorization: YOUR DEV KEY HERE

HTTP/1.x 200 OK
Server: Resin/2.1.17
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Thu, 26 Apr 2009 10:25:03 GMT

I am using the following PHP code:

$client = new Client('https://linksearch.api.cj.com', array(
    'id' => $website_id,
    'keywords' => 'sony',
));
$request = $client->get("v2/link-search?website-id={id}&keywords={keywords}");
$request->addHeader('Authorization', $dev_key);
$response = $request->send();

The problem is that with the addHeader () instruction, I get a "Bad request" response and without addHeader (), I get "Unauthorized". It seems like I'm sending my authentication data incorrectly. Does anyone know what I'm doing wrong here?

0
source share
2 answers

The real problems are here:

1) The "authorization" of the header may be case sensitive and may be lowercase.

2) 400 , - , . 400 : " , ".

+1

, $request. :

$client = new Client();
$request = new Request('POST', 'http://someuri/path/here');

$client:

$response = $client->send($request);
0

All Articles