问题描述
|
我正在尝试做的是让我的用户输入电话号码和消息,然后将其发布到发送消息的文本营销人员。
目前,如果我使用response.redirect消息意义。
response.redirect(\"http://www.textmarketer.biz/gateway/?username=*****&password=*****&message=test+message&orig=test&number=447712345678\")
但是,我不想将用户发送到那里。我要做的就是将数据发布到url,目前仅此而已,用户停留在当前页面上。
有什么帮助吗?
解决方法
实际上,您不必执行此服务器端(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,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()
,不要在服务器端执行此操作,而在客户端使用AJAX。
jQuery ajax库非常好。
,您必须使用webrequest类。请参阅http://msdn.microsoft.com/en-us/library/debx8sh9.aspx