我已正确登录并立即获取该针,因此我仍将其视为进度 有人可以查看我加密的字符串吗? 还有什么可以提出错误请求'意思?
首先,我获得了AccessToken,
它会生成这个签名库
' GET&安培; HTTPS%3A%2F%2Fetws.etrade.com%2Foauth%2Frequest_token&安培; oauth_callback%3Doob%26oauth_consumer_key%3Dc5164d11e1a0a23901d75e7aa1993085%26oauth_nonce%3D565e334127934d65aa4375d0cd2770a1%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1502146468%26oauth_version%3D1 0.0'
然后它调用执行此行的SignContext
signingContext.SignatureBase = authContext.GenerateSignatureBase();
生成此签名库
' GET&安培; HTTPS%3A%2F%2Fetws.etrade.com%2Foauth%2Frequest_token&安培; oauth_callback%3Doob%26oauth_consumer_key%3Dc5164d11e1a0a23901d75e7aa1993085%26oauth_nonce%3D565e334127934d65aa4375d0cd2770a1%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1502146468%26oauth_version%3D1 0.0'
然后它获得了引脚。
然后它调用ExchangeRequestTokenForAccessToken
它会生成这个签名库
' GET&安培; HTTPS%3A%2F%2Fetws.etrade.com%2Foauth%2Faccess_token&安培; oauth_consumer_key%3Dc5164d11e1a0a23901d75e7aa1993085%26oauth_nonce%3De63bba497c24492ab0d60366526c781a%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1502146597%26oauth_token%3D6WHEWvcaVYx59bRxzic%252FXJGGYrz4TGdH5uvlfNCdkOY%253D %26oauth_verifier%3DNHD85%26oauth_version%3D1.0'
然后使用此签名库再次签署上下文
' GET&安培; HTTPS%3A%2F%2Fetws.etrade.com%2Foauth%2Faccess_token&安培; oauth_consumer_key%3Dc5164d11e1a0a23901d75e7aa1993085%26oauth_nonce%3De63bba497c24492ab0d60366526c781a%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1502146597%26oauth_token%3D6WHEWvcaVYx59bRxzic%252FXJGGYrz4TGdH5uvlfNCdkOY%253D %26oauth_verifier%3DNHD85%26oauth_version%3D1.0'
然后我试着得到A
的报价
有了这个签名基础
' GET&安培; HTTPS%3A%2F%2Fetws.etrade.com%2Fmarket%2Frest%2Fquote%2FA&安培; detailFlag%3DALL%26oauth_consumer_key%3Dc5164d11e1a0a23901d75e7aa1993085%26oauth_nonce%3D4a3640c5fc5c40b490c475a2e6c0228e%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1502146666 %26oauth_token%3D77vmxV1reXdgDJewWspVKmOduwdDsZGVvLfZBUtBSms%253D%26oauth_version%3D1.0'
检索报价失败并返回:
8/7/2017 5:57:46 PM - Header Start 8/7/2017 5:58:18 PM - 授权:OAuth
组oauth_token =' 77xmvV1reXdgDJewWspVKmOduwdDsZGVvLfZUBtBSms%3D',oauth_nonce =' 4a3640c5fc5c40b490c475a2e6c0228e',oauth_consumer_key =' c5164d11e1a0a23901d75e7aa1993085',oauth_signature_method =' HMAC-SHA1',oauth_timestamp = ' 1502146666',oauth_version =' 1.0',oauth_signature =' 2OihTU%2BphJjPuvp82lR8Z2QhE24%3D' 8/7/2017 5:58:18 PM - Header End 8/7/2017 5:58:18 PM - System.Net.WebException:远程服务器返回错误:(400) 错误的请求。在System.Net.HttpWebRequest.GetResponse()
在EquityMetrics.Retrieve.ETradeModel.GetResponse(OAuthSession 会话,字符串url)在C:{path} \ Model \ ETradeModel.cs:第94行 8/7/2017 5:58:18 PM - Pragma:no-cache apiServerName:11w44m3
nnCoection:close Transfer-Encoding:chunked Cache-Control: no-cache,no-store内容类型:application / xml日期:星期一, 2017年8月7日22:58:18 GMT服务器:Apache
答案 0 :(得分:0)
根据Oauth 1.0 spec,授权标头应使用ascii值34,这是双引号,而不是单引号。参数也应按名称的字母顺序排序。在上面的错误消息中,它看起来像是使用单引号和未排序的参数。它应如下所示(为了便于阅读,添加了换行符):
Authorization: OAuth
oauth_token="77xmvV1reXdgDJewWspVKmOduwdDsZGVvLfZUBtBSms%3D",
oauth_nonce="4a3640c5fc5c40b490c475a2e6c0228e",
oauth_consumer_key="c5164d11e1a0a23901d75e7aa1993085",
oauth_signature="2OihTU%2BphJjP",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1502146666",
oauth_version="1.0"
答案 1 :(得分:0)
一旦我从浏览器点击了URL,我就开始收到更好的错误消息,这导致了解决方案。但是如何做到这一点并不明显。
对于此标题:
Authorization: OAuth oauth_consumer_key="c6154d11e1a0a29301d75e7aa1993085",oauth_nonce="simTGhOB4T7",oauth_signature="Dij6ZXwcBda78Rk54K3k3UUfGMc%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1505152250",oauth_token="DnMnZQTQUqaJxAFJNwTy76lEaP5toiWt2QeI4POZnKY%3D",oauth_version="1.0"
在浏览器中使用此URL可获得更好的错误消息:
https://etws.etrade.com/market/rest/quote/A?oauth_consumer_key=c6154d11e1a0a29301d75e7aa1993085&oauth_nonce=simTGhOB2T7&oauth_signature=Dij6ZXwcBda78Rk54K3k3UUfGMc%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1505152250&oauth_token=DnMnZQTQUqaJxAFJNwTy76lEaP5toiWt2QeI4POZnKY%3D&oauth_version=1.0
OTOH,排序顺序在签名基础之外似乎并不重要,如规范中所述。