尝试接收WNS访问令牌时出现invalid_request错误

时间:2016-04-01 12:34:24

标签: c# visual-studio uwp win-universal-app wns

official doc中所述,我正在使用请求构建的确切顺序:

POST /accesstoken.srf HTTP/1.1
Host: login.live.com
grant_type: client_credentials
client_id:/here's my client id from dashboard/
client_secret: /here's my secret from dashboard/
scope: notify.windows.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

我得到了:

400错误请求

Cache-Control → no-store
Connection → close
Content-Length → 76
Content-Type → application/json
Date → Fri, 01 Apr 2016 11:23:08 GMT
Pragma → no-cache
Server → Microsoft-IIS/8.5
X-Content-Type-Options → nosniff
X-WLID-Error → 0x8004101C

{
    "error": "invalid_request",
    "error_description": "Invalid request parameters"
}

我正在使用在线request maker,并且必须提及它在2天前工作正常,我按预期收到令牌和到期时间。

我在商店上创建了一个新的应用程序来尝试新的client_id和client_secret,但仍然存在同样的问题,也尝试从其他具有不同外部IP的PC而没有成功。 WNS是常见的Windows服务还是我遗失了什么?

1 个答案:

答案 0 :(得分:1)

您似乎将grant_typeclient_idclient_secretscope作为请求的Header。但正如official doc中所述:

  

云服务使用“application / x-www-form-urlencoded”格式在HTTP请求正文中提交这些必需参数。您必须确保所有参数都是URL编码。

这些参数应该在HTTP请求正文和URL编码中。使用Request Maker时,您无需添加任何请求标头,因为默认Content-Typeapplication/x-www-form-urlencoded。另请注意使用网址编码client_idclient_secret。请求如下:
enter image description here

请求标头已发送:

POST /accesstoken.srf HTTP/1.1
Host: login.live.com
Accept: */*
Content-Length: 210
Content-Type: application/x-www-form-urlencoded

响应标题:

Cache-Control: no-store
Pragma: no-cache
Content-Length: 436
Content-Type: application/json
Server: Microsoft-IIS/8.5
X-Content-Type-Options: nosniff
Date: Wed, 06 Apr 2016 09:28:04 GMT
Connection: close

回复正文:

{"token_type":"bearer","access_token":"EgAaAQMAAAAEgAAAC4...y0yNTQ1NDU3MDAA","expires_in":86400}