[英]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.