以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 发送短信报错! (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=174804) |
-- 作者:ycwk -- 发布时间:2022/2/7 10:04:00 -- 发送短信报错! .NET Framework 版本:4.0.30319.42000 Foxtable 版本:2021.5.29.1 错误所在事件: 详细错误信息: 如果设置 ContentLength>0 或 SendChunked==true,则必须提供请求正文。 在 [Begin]GetResponse 之前通过调用 [Begin]GetRequestStream,可执行此操作。 登录代码如下: Dim user As String="test" Dim password As String="pasword" Dim salt As String="123" Dim tempall As String=salt & password Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(tempall,"MD5") Dim hc As New HttpClient("http://sms.yy.hn.cegn.cn:9527/session") hc.FormData.Add("user",user) hc.FormData.Add("salt",salt) hc.FormData.Add("auth",auth) Dim ret As String = hc.getData() msgbox(ret) \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' Dim desttermid As String="15312345678" Dim content As String="测试!" Dim mode As String="0" \'Dim tempall As String=salt & password \'Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(tempall,"MD5") Dim hc1 As New HttpClient("http://sms.yy.hn.cegn.cn:9527/message") hc1.FormData.Add("desttermid",desttermid) hc1.FormData.Add("content",content) hc1.FormData.Add("mode",mode) Dim ret1 As String = hc1.getData() msgbox(ret1) [此贴子已经被作者于2022/2/7 10:08:39编辑过]
|
-- 作者:有点蓝 -- 发布时间:2022/2/7 10:15:00 -- 完整的接口文档或者链接? |
-- 作者:ycwk -- 发布时间:2022/2/7 10:26:00 -- [此贴子已经被作者于2022/2/7 15:50:43编辑过]
|
-- 作者:有点蓝 -- 发布时间:2022/2/7 10:48:00 -- 表单模式加上下面代码试试 hc.ContentType = "application/x-www-form-urlencoded" 1、加密时是密码在前,随机值在后:auth=md5(pwd+salt) 2、需要获取登录时的cookie使用,可以参考这里的10楼用法:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=170483&skin=0
|
-- 作者:ycwk -- 发布时间:2022/2/7 10:53:00 -- 按照上面提示的1 做了, hc.ContentType = "application/x-www-form-urlencoded" 也加了,但是现在在登录的时候都报错,还没到后面发送呀。 |
-- 作者:有点蓝 -- 发布时间:2022/2/7 10:57:00 -- 找对方要.net的实例代码 |
-- 作者:ycwk -- 发布时间:2022/2/7 11:11:00 -- 这是很久以前写的,可以执行成功,请问这段代码现在可以简化吗? Dim str_name As String="名字" Dim str_sign As String="中心" \'Dim str_SearchTable As String=args(2) Dim str_tel As String="13312345678" Dim str_content As String="计算机测试" \'Dim str_ReplyMessage As String=args(4) \'用于判断是否需要接收发送成功的 弹出提醒 \'Dim str_DeptName As String =args(5) \'传递部门过来 str_content=str_sign & "提示您:" & str_content \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' Dim user As String = "yyy" Dim salt As String = "123" Dim str_temp As String = "password" & salt Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_temp,"MD5").ToUpper Dim msg As String = "user=" & user & "&salt=" & salt & "&auth=" & auth \'输入请求传参数 \'msgbox(msg) \'\'\'\'\'\'\'\'\'\'\'\'\'\'以下为POST方法 为了登陆 Dim req As System.Net.HttpWebRequest = System.Net.WebRequest.Create("http://10.10.10.10:9527/session") req.Method = "POST" req.timeout = 5000 req.C req.ContentLength = msg.Length Dim cookieCon As new System.Net.CookieContainer() \'声明cookiescon req.CookieContainer = cookieCon \'给req的container赋值 Dim postBytes() As Byte = Encoding.UTF8.GetBytes(msg) Dim requestStream As Object = req.GetRequestStream() requestStream.Write(postBytes, 0, postBytes.Length) requestStream.Close() Dim pos As System.Net.WebResponse = req.GetResponse() Dim cookieheader As String = req.CookieContainer.GetCookieHeader(new Uri("http://10.10.10.10:9527/")) Dim mycookie = req.CookieContainer \'msgbox(cookieheader ) \'显示cookie Dim stm As System.IO.Stream = pos.GetResponseStream() Dim reader As New System.IO.StreamReader(stm,encoding.utf8) Dim str As String = reader.ReadToEnd stm.Dispose() \'msgbox(str) \'查收errorcode 的值 \'\'\'\'\'\'\'\'\'\'\'\'\'\'以下为POST方法 为了发短信 Dim desttermid As String = str_tel Dim content As String = str_content Dim mode As String = "2" Dim msg3 As String = "desttermid=" & desttermid & "&c&mode=" & mode \'输入请求传参数 \'msgbox(msg3) \'以下为POST方法 \'为了发短信 Dim req3 As System.Net.HttpWebRequest = System.Net.WebRequest.Create("http://10.10.10.10:9527/message") req3.Method = "POST" req3.timeout = 5000 req3.C \'req3.ContentLength = msg3.Length \'Dim cookieCon As new System.Net.CookieContainer() \'声明cookiescon req3.CookieContainer = mycookie \'给req的container赋值 \'dim postBytes() As Byte = Encoding.UTF8.GetBytes(msg3) Dim postBytes3() As Byte= Encoding.UTF8.GetBytes(msg3) Dim requestStream3 As Object = req3.GetRequestStream() \'msgbox(1) requestStream3.Write(postBytes3, 0, postBytes3.Length) \'msgbox(2) requestStream3.Close() Dim pos3 As System.Net.WebResponse = req3.GetResponse() Dim cookieheader3 As String = req3.CookieContainer.GetCookieHeader(new Uri("http://10.10.10.10:9527/")) mycookie = req3.CookieContainer \'msgbox(cookieheader3) Dim stm3 As System.IO.Stream = pos3.GetResponseStream() Dim reader3 As New System.IO.StreamReader(stm3,encoding.utf8) Dim str3 As String = reader3.ReadToEnd stm3.Dispose() \'msgbox(str3) \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' \'以下为DELETE方法 Dim req2 = System.Net.WebRequest.Create("http://10.10.10.10:9527/session") req2.Method = "DELETE" req2.timeout = 5000 req2.C req2.CookieContainer = mycookie Dim pos2 As System.Net.WebResponse = req2.GetResponse() Dim stm2 As System.IO.Stream = pos2.GetResponseStream() Dim reader2 As New System.IO.StreamReader(stm2,encoding.utf8) Dim str2 As String = reader2.ReadToEnd stm2.Dispose() \'msgbox(str2) 这是delete方法的回执
|
-- 作者:有点蓝 -- 发布时间:2022/2/7 11:47:00 -- 简化不了,如果这个代码可以使用,建议还是继续使用好了。 |