如何在 .net vb 中发送 POST?

发布于 2024-11-09 01:06:50 字数 333 浏览 0 评论 0原文

我想做的是让我的用户输入电话号码和消息,然后将其发布给发送消息的文本营销人员。

目前,如果我使用响应。重定向消息感。

response.redirect("http://www.textmarketer.biz/gateway/?username=*****&password=*****&message=test+message&orig=test&number=447712345678")

但是,我不想将用户发送到那里。我想做的就是将数据发布到 url,这就是现在的全部内容,用户停留在当前页面上。

有什么帮助吗?

What i am trying to do is get my user to enter in a phone number and message and then post it to text marketer which send the message.

at the moment if i use a response.redirect the message sense..

response.redirect("http://www.textmarketer.biz/gateway/?username=*****&password=*****&message=test+message&orig=test&number=447712345678")

However, i do not want to send the user there. all i want to do it post the data to the url and that's all for now and the user stay on the current page.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光暖心i 2024-11-16 01:06:50

实际上,您不必执行此服务器端 (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() 后,您可以从远程服务器检索输出并将其呈现在您的页面上。但如果您想发布并重定向到远程网址,那么我想您应该使用第一种方法。

编辑:

在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

update2:

在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()

actually, you don't have to do this server side (vb), just plain html will do the trick:

<html>
    <body>
        <form action="http://google.com" method="post">
            <input type="hidden" value="somevalue"/>
            <input Type="submit" value="Submit"/>
        </form>
    </body>
</html>

this will post the data (and in effect, redirect) to google.com.

Maybe you could use client script (jQuery) - $.ajax() or $.post(). but I think you will face cross domain restrictions (there is a workaround but its not that clean and straightforward).

Another is using the HttpWebRequest class. This is server side and the post will originate from your server instead of the client (as what the 1st approach will do). upon calling request.GetResponse(), you can retrieve the output from the remote server and render it on your page. But if you want to post and redirect to the remote url then I guess you should use the first approach.

EDIT:

try this in 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

update2:

a GET request using HttpWebRequest in VB.net.

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()
静谧 2024-11-16 01:06:50

你必须使用 webrequest 类。请参阅http://msdn.microsoft.com/en-us/library/debx8sh9。 ASPX

you have to use the webrequest class. refer http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

兔姬 2024-11-16 01:06:50

不要在服务器端执行此操作,而是使用 AJAX 执行此操作。

jQuery ajax 库非常好。

Don't do this server side, but client side using AJAX.

The jQuery ajax library is quite good.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文