c# - Http 请求状态代码 405 ReasonPhrase : '' Youtube APi

标签 c# api httprequest response http-error

我尝试发送这两个请求,但我只收到标题中列出的错误作为响应。 我对谷歌服务器的两个网络请求是这样的:

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
}

最佳答案

如果您不能使用 Google.Apis.YouTube.v3 Client Library在你的项目中,使用 lib 创建一个测试项目,做你想做的并使用 fiddler 嗅探流量

关于c# - Http 请求状态代码 405 ReasonPhrase : '' Youtube APi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32848517/

相关文章:

ios - 等到多个网络请求都执行完毕——包括它们的完成 block

c# - 如何执行真正耗时的方法? asp.net(定时)

c# - 使用MultiMatch进行Elasticsearch/Nest搜索,所有其他字段均默认增强

c++ - 有没有办法检测哪个应用程序获得焦点?

Java - 从 URL 的视频中获取片段

curl - 将以下 Paypal curl 命令转换为 axios?

c# - 在富文本框中创建换行符

c# - 当属性设置为值时禁用行选择数据网格 WPF

ios - 带有附件下载 API 支持的一次性临时电子邮件

javascript - 用于进行 API 调用的 JS 函数