实际上,您不必做这个服务器端 (vb),只需简单的 html 即可:
<html>
<body>
<form action="http://google.com" method="post">
<input type="hidden" value="somevalue"/>
<input Type="submit" value="Submit"/>
</form>
</body>
</html>
这会将数据(实际上是重定向)发布到 google.com。
也许您可以使用客户端脚本 (jQuery) - $.ajax() 或 $.post()。但我认为您将面临跨域限制(有一种解决方法,但不是那么干净和直接)。
另一个是使用 HttpWebRequest 类。这是服务器端,帖子将来自您的服务器而不是客户端(就像第一种方法一样)。调用 request.GetResponse() 后,您可以从远程服务器检索输出并将其呈现在您的页面上。但是,如果您想发布并重定向到远程 url,那么我想您应该使用第一种方法。
编辑:
在 VB 中试试这个:
Option Infer On
Imports System.Net
Imports System.Text
Public Class Test
Private Sub TESTRUN()
Dim s As HttpWebRequest
Dim enc As UTF8Encoding
Dim postdata As String
Dim postdatabytes As Byte()
s = HttpWebRequest.Create("http://www.textmarketer.biz/gateway/")
enc = New System.Text.UTF8Encoding()
postdata = "username=*****&password=*****&message=test+message&orig=test&number=447712345678"
postdatabytes = enc.GetBytes(postdata)
s.Method = "POST"
s.ContentType = "application/x-www-form-urlencoded"
s.ContentLength = postdatabytes.Length
Using stream = s.GetRequestStream()
stream.Write(postdatabytes, 0, postdatabytes.Length)
End Using
Dim result = s.GetResponse()
End Sub
End Class
更新2:
在 VB.net 中使用 HttpWebRequest 的 GET 请求。
Dim s As HttpWebRequest
Dim username = "username=" + HttpUtility.UrlEncode("yourusername")
Dim password = "password=" + HttpUtility.UrlEncode("yourp@assword)!==&@(*#)!@#(_")
Dim message = "message=" + HttpUtility.UrlEncode("yourmessage")
Dim orig = "orig=" + HttpUtility.UrlEncode("dunno what this is")
Dim num = "number=" + HttpUtility.UrlEncode("123456")
Dim sep = "&"
Dim sb As New StringBuilder()
sb.Append(username).Append(sep).Append(password).Append(sep)
sb.Append(message).Append(sep).Append(orig).Append(sep).Append(num)
s = HttpWebRequest.Create("http://www.textmarketer.biz/gateway/?" + sb.ToString())
s.Method = "GET"
Dim result = s.GetResponse()