HTTP接口发送短信还是选择get 方式

笔者经过几天的SDK短信调试,发现post提交的数据经常乱码,特别是在utf-8的编码下,根据测试get方式可以不乱

笔者的原代码如下:

<%

'--------------------------------------
'发送短信
'参数:mobile 手机,content 内容,ext 扩展码,stime 定时时间,rrid 唯一标识如为空系统返回
'http://sdk2.entinfo.cn/z_send.aspx?sn=SDK-TTS-010-05314&pwd=947623&mobile=13590310306&content=yangzong1&ext=&Stime=&Rrid=
'--------------------------------------
function Send_sms(mobile,content,ext,stime,rrid)
 '调用call Send_sms("手机号码","短信发送内容","","","")


 dim urlstr,sms_price,wt_Status,SenData
 dim sms_Erro,wt_Status2
 
urlstr="sn=用户名&pwd=密码&mobile="&mobile&"&content="&content&"&ext=&Stime=&Rrid=&random="&random()
 SenData="发送网址?"&urlstr
 'response.Write urlstr
 '获取发送状态  
 'wt_Status=PostData(urlstr,"gb2312")   
'response.Write SenData
 '  response.Redirect SenData
  wt_Status=getHTTPPage(SenData,"gb2312")
 'response.Write wt_Status
 'response.Write "<br >urlstr:"&urlstr
' response.End()
 
' ' 'response.Write wt_Status
 'response.End()
 
 Set urlstr = Nothing
 Set sms_Erro = Nothing
end function
 


'************************************************

'post 方式获取数据
Function PostData(PostUrl,PostStr,PostMode,websiteCharset)
Dim Http
Set Http = Server.CreateObject("msxml2.XMLHTTP")
With Http
.Open "POST",PostUrl,False
.SetRequestHeader "Content-Length",Len(PostStr)
.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
.SetRequestHeader "Referer",PostUrl
.Send PostStr
If PostMode=0 Then
PostData = .ResponseBody
Else
if websiteCharset= "" then
websiteCharset="utf-8"
end if
PostData = BytesToBstr(.ResponseBody,websiteCharset)
End If
End With
Set Http = Nothing
End Function

'************************************************
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode = 3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function

 '************************************************
'获取随机代码
function random() 
    Randomize
 random = Int(90000000*rnd)+100000
end function


'****************************************************
'************   get 方式获取代码    *******************
'****************************************************
Function GetHttpPage(HttpUrl,websiteCharset)
    'On Error Resume Next
   If IsNull(HttpUrl)=True Or Len(HttpUrl)<18   Then
      GetHttpPage=False_notic
      Exit Function
   End If
   Dim Http
   Set Http=server.createobject("MSXML2.XMLHTTP")
   Http.open "GET",HttpUrl,False
   Http.Send()
   If Http.Readystate<>4 then
      Set Http=Nothing
      GetHttpPage="获取数据错误"
      Exit function
   End if
   if websiteCharset="" then
   websiteCharset="GB2312"
   end if
   getHTTPPage=bytesToBSTR(Http.responseBody,websiteCharset)  
   Set Http=Nothing
   If Err.number<>0 then
      Err.Clear
   End If
End Function

%>

    相关文章

评论

发表新评论

此内容将保密,不会被其他人看见。
点击刷新验证码
  • 可用的 UBB 标签:
  • 留言最长字数:1000。