gpt4 book ai didi

asp.net - Windows 推送通知的 AccessToken 返回错误请求 400

转载 作者:行者123 更新时间:2023-12-01 11:45:45 25 4
gpt4 key购买 nike

请帮忙!!无法弄清楚为什么 MSDN 给出的这个简单代码不起作用....

我在 GetAccessToken() 中使用以下代码,如 this MSDN article 中给出的那样获取要在 Windows 通知中使用的访问 token ,但它返回“Bad Request 400”

PACKAGE_SECURITY_IDENTIFIER、CLIENT_SECRET 是应用注册到 Windows Store Dashboard 时获得的值

string urlEncodedSid = HttpUtility.UrlEncode(PACKAGE_SECURITY_IDENTIFIER);
string urlEncodedSecret = HttpUtility.UrlEncode(CLIENT_SECRET);

string body = String.Format("grant_type=client_credentials&client_id={0}&client_secret={1}&scope=notify.windows.com", urlEncodedSid, urlEncodedSecret);

string response;

using (WebClient client = new WebClient())
{
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
response = client.UploadString("https://login.live.com/accesstoken.srf", body);
}

任何帮助将不胜感激......

最佳答案

我怀疑问题与不正确的包标识符和/或不正确的客户端密码有关。

来自 MSDN 页面 Push notification service request and response headers :

RESPONSE          DESCRIPTION
--------------- --------------------------
200 OK The request was successful.
400 Bad Request The authentication failed.

更新 - 我使用假凭据运行问题中的代码。

这是原始 HTTP 请求:

POST https://login.live.com/accesstoken.srf HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: login.live.com
Content-Length: 88
Expect: 100-continue
Connection: Keep-Alive

grant_type=client_credentials&client_id=test&client_secret=test&scope=notify.windows.com

这是服务器的原始响应:

HTTP/1.1 400 Bad Request
Cache-Control: no-store
Content-Length: 66
Content-Type: application/json
Server: Microsoft-IIS/7.5
X-WLID-Error: 0x80045A78
PPServer: PPV: 30 H: BAYIDSLGN2A055 V: 0
Date: Thu, 21 Mar 2013 12:34:19 GMT
Connection: close

{"error":"invalid_client","error_description":"Invalid client id"}

您会注意到响应是 400。还有一些 json 指示错误类型。在我的情况 中,错误是无效的客户端ID。您可能想查看您的回复 - 它会告诉您发生了什么。

我用了Fiddler调试请求/响应。

关于asp.net - Windows 推送通知的 AccessToken 返回错误请求 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15517822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com