PHP + Guzzle,在标题中发送授权密钥 [英] PHP + Guzzle, Sending Authorization Key in Header

查看:65
本文介绍了PHP + Guzzle,在标题中发送授权密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Guzzle的新手,正在尝试生成以下REST调用:

I'm new to Guzzle and I'm attempting to generate 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

我正在使用以下PHP代码:

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();

这里的问题是,使用addHeader()语句可获得响应"Bad Request",而没有addHeader()则可获得未经授权".看来我没有正确发送身份验证信息.有人知道我在这里做错了吗?

The issue here is that with the addHeader() statement I get the response "Bad Request" and without addHeader() I am getting "Unauthorized". It would seem that I am not properly sending my authentication information. Does anyone know what I'm doing wrong here?

推荐答案

此处的实际问题是:

1)标头授权"可能区分大小写,并且可能需要小写.

1) The header 'authorization' may be case sensitive and may need to be lowercase.

2)如果任何请求参数不正确,甚至您的网站ID,都将引发400错误.错误400表示请求由于身份验证以外的原因而无效."

2) A 400 error will be thrown if any of the request parameters are incorrect, even your website-id. A 400 error means "The request was invalid for reasons other than authentication."

这篇关于PHP + Guzzle,在标题中发送授权密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆