获取服务器响应时出现 404 错误 vb.net

404 error while getting server response vb.net

我完全是 webrequest 的初学者,所以我不知道是什么原因导致我收到错误。

我尝试按照 webrequest 的微软教程在表单上登录,但是当我想要获得服务器响应时,出现以下错误:

"the remote server returned an error (404) not found"

所以我知道我使用的 URL 确实存在,然后想知道代码的哪一部分是错误的。也许是因为我正在执行一个 HTTPS 请求,这与教程不同,它改变了一些东西? 另外,我对直接从服务器获得答案感到有点困惑:难道不应该有一种触发器来知道服务器何时回答吗?

Dim request = WebRequest.Create("https://ssl.vocabell.com/mytica2/login")
request.Credentials = CredentialCache.DefaultCredentials
request.Method = "POST"
Dim byteArray = Encoding.UTF8.GetBytes("_username=x&_password=x")
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim reponse = request.GetResponse() 'ERROR
MsgBox(CType(reponse, HttpWebResponse).StatusDescription)
Using ds = reponse.GetResponseStream
     Dim reader = New StreamReader(ds)
     MsgBox(reader.ReadToEnd)
End Using
reponse.Close()

感谢您抽出宝贵时间,如果您有关于该主题的任何相关教程,我将很乐意阅读!

您提到的页面确实存在并使用 HTTPS,但是如果您查看其中的表单标记,它是这样的:

<form class="login-form form-horizontal" action="/mytica2/login_check" method="POST">

这意味着它不会 post 将表单返回到与页面相同的 URL,而是将其发送到包含在 "action" 中的 URL属性。如果您尝试使用您的代码来模拟登录表单的提交,那么看起来您需要将 POST 请求发送到 https://ssl.vocabell.com/mytica2/login_check