[英]How To Pass Values in VB.net HTTP Function?
我想创建一个小的实用程序,用户可以在其中通过txtlocal API发送SMS。 VB.net的txtlocal优惠代码段。 我只创建了一个简单的表单并复制粘贴了代码,“贷方余额”检查功能可以正常工作,但无法通过Win Form发送SMS。 这是代码段-
txtlocal的代码段-
Private Function SendSMS_txtLocal(ByVal Test As Boolean, _
ByVal From As String, _
ByVal Message As String, _
ByVal SendTo As String, _
ByVal URL As String) As String
' Send a message using the txtLocal transport
Const TransportURL As String ="http://www.txtlocal.com/sendsmspost.php"
Const TransportUserNameAs String ="me@myemail.com"
Const TransportPasswordAs String ="mypassword"
Const TransportVerboseAs Boolean =True
Dim strPost As String
' Build POST String
strPost = "uname=" + TransportUserName _
+ "&pword=" + TransportPassword _
+ "&message=" + System.Web.HttpUtility.UrlEncode(Message) _
+ "&from=" + From _
+ "&selectednums=" + SendTo
If URL "" Then
strPost += "&url=" + URL
End If
If Test = True Then
strPost += "&test=1"
End If
If TransportVerbose =True Then
strPost += "&info=1"
End If
' Create POST
Dim request As WebRequest = WebRequest.Create(TransportURL)
request.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(strPost)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
' Get the response.
Dim response As WebResponse = request.GetResponse()
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServerAs String = reader.ReadToEnd()
' Clean upthe streams.
reader.Close()
dataStream.Close()
response.Close()
' Return result to calling function
If responseFromServer.Length > 0 Then
Return responseFromServer
Else
Return CType(response, HttpWebResponse).StatusDescription
End If
End Function
我这样调用函数-
SendSMS_txtLocal(0, TextBox1.Text, TextBox2.Text, TextBox3.Text, "http://www.txtlocal.com/sendsmspost.php")
这是我的表格设计-
请提出建议-代码有什么问题。
谢谢与最好的问候
从外观上看,您调用的函数是错误的。 尝试:
SendSMS_txtLocal(0, TextBox1.Text, TextBox2.Text, TextBox3.Text, "??")
您添加的URL未被用作URL,而是被发送到要发送给它们的信息字符串中的txtlocal
,不知道其用途或目的,请在其网站上阅读?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.