必须使用适当的属性或方法(TwitchAPI)修改"Accept"标头

Ele*_*ree 6 vb.net exception httpwebrequest winforms

正如您在标题中看到的那样,我的问题是在添加标题时出现异常.我要做的是向公众TwitchAPI发送授权请求.这是我要翻译的请求:

curl -H 'Accept: application/vnd.twitchtv.v3+json' 
-H 'Authorization: OAuth <access_token>' \ 
-X GET https://api.twitch.tv/kraken/channel
Run Code Online (Sandbox Code Playgroud)

当我添加Accept标头时,我的脸上会弹出这个异常(标题).我不确定我是否正确翻译了这个,但这是我现在的代码:

Dim wr = CType(WebRequest.Create("https://api.twitch.tv/kraken/channel"), HttpWebRequest)
wr.Method = "GET"
wr.Headers.Add("Authorization: OAuth <oauth_token>")
wr.Headers.Add("Accept: application/vnd.twitchtv.v3+json")
Return CType(wr.GetResponse(), HttpWebResponse)
Run Code Online (Sandbox Code Playgroud)

oauth_token是我的访问令牌,谁能为我解决这个问题?真的让我的屁股试图找出这么简单的事情,谢谢!

  • 哦,而且,当我删除标题(我实际上认为是不必要的)时,它表示未经授权,使用正确的访问令牌.

小智 7

HttpWebRequest班有一个特定Accept设置的"接受"头属性

Dim wr = CType(WebRequest.Create("https://api.twitch.tv/kraken/channel"), HttpWebRequest)
wr.Method = "GET"
wr.Headers.Add("Authorization: OAuth <oauth_token>")
wr.Accept = "application/vnd.twitchtv.v3+json"
Return CType(wr.GetResponse(), HttpWebResponse)
Run Code Online (Sandbox Code Playgroud)