-1

我现在可以正确登录并获得密码,所以我仍然将其视为进步。
有人可以检查我正在加密的字符串吗?
“错误请求”还有什么含义?

首先,我得到了
生成这个签名库 的 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'

然后它调用执行此行的 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'

然后它得到引脚。


然后它调用生成此签名库的 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 - Authorization: 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' 2017 年 8 月 7 日下午 5:58:18 - 标题结束 2017 年 8 月 7 日 5:58 :18 PM - System.Net.WebException:远程服务器返回错误:(400)错误请求。在 System.Net.HttpWebRequest.GetResponse()
at EquityMetrics.Retrieve.ETradeModel.GetResponse(OAuthSession session, String url) in C:{path}\Model\ETradeModel.cs:line 94
8/7/2017 5:58:18 PM - 编译指示:
nnCoection:关闭传输编码:分块缓存控制:无缓存,无存储内容类型:应用程序/xml 日期:星期一,2017 年 8 月 7 日 22:58:18 GMT 服务器:Apache

4

2 回答 2

0

根据Oauth 1.0 规范,授权标头应使用 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"
于 2017-08-09T22:58:15.173 回答
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,排序顺序似乎并不重要,在签名的基础之外,如规范中所述。

于 2017-09-11T18:38:58.060 回答