远程服务器返回错误(403),VB.NET [英] The remote server returned an error (403), VB.NET
本文介绍了远程服务器返回错误(403),VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
cardName = MainMenu.txt_name.Text & "+" & Me.cmb_sets.SelectedItem
MsgBox(cardName)
Dim strURL As String = "https://www.cardmarket.com/en/YuGiOh/Products/Singles/Ra+Yellow+Mega+Pack/Yubel+-+The+Ultimate+Nightmare"
Dim strOutput As String = ""
Dim wrResponse As WebResponse
Dim wrRequest As WebRequest = HttpWebRequest.Create(strURL)
wrResponse = wrRequest.GetResponse()
Using sr As New StreamReader(wrResponse.GetResponseStream())
strOutput = sr.ReadToEnd()
' Close StreamReader
sr.Close()
End Using
错误是:远程服务器返回错误:(403) Forbidden."我看过其他一些有同样错误的人,但找不到具体的修复方法.tia - 奥布里
The error is : "The remote server returned an error: (403) Forbidden." I have looked at some other people with the same error but cannot find a specific fix. tia - Aubrey
推荐答案
您需要指定一个 Web 客户端.例如:MS Edge、Firefox、Internet Explorer
You need to specify a web client. ex: MS Edge, Firefox, Internet Explorer
Imports System.Net.Http
Public Class Form1
Private Async Sub Form1_LoadAsync(sender As Object, e As EventArgs) Handles MyBase.Load
Dim res As String = Await (GetPageAsync("https://www.cardmarket.com/en/YuGiOh/Products/Singles/Ra+Yellow+Mega+Pack/Yubel+-+The+Ultimate+Nightmare"))
End Sub
Async Function GetPageAsync(ByVal URL As String) As Task(Of String)
Dim client As New HttpClient
Dim stroutput As String = ""
client.DefaultRequestHeaders.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
Try
stroutput = Await (client.GetStringAsync(New Uri(URL)))
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
Return stroutput
End Function
End Class
这篇关于远程服务器返回错误(403),VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文