0

我想创建一个小实用程序,用户可以通过 txtlocal API 发送短信。用于 VB.net 的 txtlocal 提供代码片段。我只是创建一个简单的表单并复制粘贴代码,信用余额检查功能工作正常,但通过 Win Form 发送短信不起作用。这是代码片段 -

来自 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")

这是我的表单设计 -

在此处输入图像描述

请建议 - 代码有什么问题..

谢谢和最好的问候

4

1 回答 1

0

从外观上看,您调用该函数是错误的。尝试:

SendSMS_txtLocal(0, TextBox1.Text, TextBox2.Text, TextBox3.Text, "??")

您添加的 URL 没有用作 URL,它被发送到txtlocal您发送给他们的信息字符串中,不知道它的用途或目的是什么,在他们的网站上阅读?

于 2015-04-24T09:29:04.247 回答