Foxtable(狐表)用户栏目专家坐堂 → [求助]第三方平台POST模式发送短信的问题


  共有3404人关注过本帖树形打印复制链接

主题:[求助]第三方平台POST模式发送短信的问题

帅哥哟,离线,有人找我吗?
zwjfx
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:146 积分:2622 威望:0 精华:0 注册:2014/3/18 12:20:00
[求助]第三方平台POST模式发送短信的问题  发帖心情 Post By:2014/9/16 23:52:00 [只看该作者]

下面是平台提供的示例代码,要怎么才能转成狐表的,直接测试是报错

VB.net示例

Module SendEsms
 
    Sub Main()
        Dim strContent As String = "测试"
Dim uid As String = "test"
Dim pwd As String = "fa246d0262c3925617b0c72bb20eeb1d"
Dim mobile As String = "15900001111,13900001111"
'GET 方式
        Dim getReturn As String = doGetRequest("http://api.sms.cn/mt/?uid="+uid+"&pwd="+pwd+"&mobile="+mobile+"&cmargin: 0px; padding: 0px; color: rgb(102, 102, 102); font-family: 宋体; font-size: 12px; line-height: 30px;">        Console.WriteLine("Get response is: " & getReturn)
 
'POST 方式
        Dim sbTemp As System.Text.StringBuilder = New System.Text.StringBuilder()
        sbTemp.Append("uid="+uid+"&pwd="+pwd+"&mobile="+mobile+"&cmargin: 0px; padding: 0px; color: rgb(102, 102, 102); font-family: 宋体; font-size: 12px; line-height: 30px;">        Dim bTemp() As Byte = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString())
        Dim postReturn As String = doPostRequest("http://api.sms.cn/mt/", bTemp)
        Console.WriteLine("Post response is: " + postReturn)
 
 
    End Sub
 
    '发送HTTP GET请求得结果
    Private Function doGetRequest(ByVal url As String) As String
        Dim strReturn As String = ""
        Dim hwRequest As System.Net.HttpWebRequest
        Dim hwResponse As System.Net.HttpWebResponse
        Try
            hwRequest = System.Net.HttpWebRequest.Create(url)
            hwRequest.Timeout = 5000
            hwRequest.Method = "GET"
            hwRequest.C
 
            hwResponse = hwRequest.GetResponse()
            Dim srReader As System.IO.StreamReader = New System.IO.StreamReader(hwResponse.GetResponseStream(), System.Text.Encoding.ASCII)
            strReturn = srReader.ReadToEnd()
            srReader.Close()
            hwResponse.Close()
 
        Catch
        End Try
        Return strReturn
    End Function
 
    '发送HTTP POST请求得结果
    Private Function doPostRequest(ByVal url As String, ByVal bData() As Byte) As String
        Dim strReturn As String = ""
        Dim hwRequest As System.Net.HttpWebRequest
        Dim hwResponse As System.Net.HttpWebResponse
        Try
            hwRequest = System.Net.HttpWebRequest.Create(url)
            hwRequest.Timeout = 5000
            hwRequest.Method = "POST"
            hwRequest.C
            hwRequest.ContentLength = bData.Length
 
            Dim smWrite As System.IO.Stream = hwRequest.GetRequestStream()
            smWrite.Write(bData, 0, bData.Length)
            smWrite.Close()
 
            hwResponse = hwRequest.GetResponse()
            Dim srReader As System.IO.StreamReader = New System.IO.StreamReader(hwResponse.GetResponseStream(), System.Text.Encoding.ASCII)
            strReturn = srReader.ReadToEnd()
            srReader.Close()
            hwResponse.Close()
        Catch
 
        End Try
        Return strReturn
    End Function
 
End Module

 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/9/17 8:36:00 [只看该作者]

放到全局代码里面去

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/9/17 9:04:00 [只看该作者]


 回到顶部