我正在尝试与HMRC增值税测试API进行通信,但是每当上载NameValueCollection
时尝试获得响应时,我都会收到 403 Forbidden (禁止使用),但仍在浏览器每次都可以使用。
我正在显示我正在使用的代码,它的行号为:
Dim responseBytes As Byte() = client.UploadValues(address, "POST", values)
我在VS2017中使用VB.net,但如今对VB.net的支持似乎很少。
Dim client = New WebClient()
Dim address = New Uri(String.Format("https://test-api.service.hmrc.gov.uk/oauth/authorize"))
Dim client_id As String = "MY-CLIENT-ID"
Dim scope As String = "hello"
Dim redirecturi As String = "https://www.example.com/redirect/"
Dim values = New NameValueCollection
values.Add("client_id", client_id)
values.Add("response_type", "code")
values.Add("scope", scope)
values.Add("redirect_uri", redirecturi)
Dim responseBytes As Byte() = client.UploadValues(address, "POST", values)
'Get response
Dim response As String = Encoding.UTF8.GetString(responseBytes)
回来
System.Net.WebException: 'The remote server returned an error: (403) Forbidden.'
n.b。显然,我没有显示我的实际Client-ID,并且url和querystring在浏览器中工作正常。