【发布时间】:2015-12-27 04:50:45
【问题描述】:
我尝试发送这两个请求,但我只收到标题中列出的错误作为响应。 我对谷歌服务器的两个网络请求是这样的:
HttpClient http = new HttpClient();
HttpResponseMessage response = await http.GetAsync("https://accounts.google.com/o/oauth2/token?code="+localSettings.Values["AccessKey"]+"&client_id=XX-XXXXXXXXXX.apps.googleusercontent.com&client_secret=XXXXX-XXXX&redirect_uri=http://localhost/oauth2callback&grant_type=authorization_code");
//response.EnsureSuccessStatusCode();
Debug.WriteLine(response.ToString());
HttpResponseMessage response1 = await http.GetAsync("https://content.googleapis.com/youtube/v3/subscriptions?part=id&maxResults=10&mine=true&key="+localSettings.Values["AccessKey"]);
Debug.WriteLine(response1.ToString());
我从调试器得到以下输出:
StatusCode: 405, ReasonPhrase: '', Version: 2.0, Content: System.Net.Http.StreamContent, Headers:
{
server: GSE
alt-svc: quic=":443"; p="1"; ma=604800
cache-control: max-age=0, private
accept-ranges: none
date: Tue, 29 Sep 2015 16:05:03 GMT
x-frame-options: SAMEORIGIN
vary: Accept-Encoding
x-content-type-options: nosniff
alternate-protocol: 443:quic,p=1
x-xss-protection: 1; mode=block
content-type: application/json
expires: Tue, 29 Sep 2015 16:05:03 GMT
}
StatusCode: 400, ReasonPhrase: '', Version: 2.0, Content: System.Net.Http.StreamContent, Headers:
{
server: GSE
alt-svc: quic=":443"; p="1"; ma=604800
cache-control: max-age=0, private
accept-ranges: none
date: Tue, 29 Sep 2015 16:05:04 GMT
x-frame-options: SAMEORIGIN
vary: X-Origin
vary: Origin
vary: Accept-Encoding
x-content-type-options: nosniff
alternate-protocol: 443:quic,p=1
x-xss-protection: 1; mode=block
content-type: application/json; charset=UTF-8
expires: Tue, 29 Sep 2015 16:05:04 GMT
}
【问题讨论】:
-
能否请您发布完整的错误信息?
-
@helencrump 更新了带有调试输出的帖子
-
您尝试访问的 URL 是否有效?
-
@helencrump 我真的不知道我对从 youtube api 2.0 到 3.0 的机会感到困惑:这是来自谷歌的指南:developers.google.com/youtube/2.0/… 我不知道我做错了什么看来我使用的是正确的模式。第 5 步是刷新和访问令牌的交换授权代码,这对我不起作用。
-
我不敢相信没有人试图解释 HTTP 错误 405 的实际含义。这意味着您使用了错误的请求动词(
GET、POST、PUT等)。修复第一个错误可能很简单,只需将GetAsync替换为PostAsync。就目前而言,第二个错误似乎是第一个失败的连锁反应。我没有对此进行详细研究,但您可能需要从对第一个请求的响应中提取一些数据并将其传递给第二个请求。
标签: c# api httprequest response http-error