Foxtable(狐表)用户栏目专家坐堂 → 短信接口中请在request请求中附带登出后的cookies使用,这是什么意思?


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

主题:短信接口中请在request请求中附带登出后的cookies使用,这是什么意思?

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


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

1、你的delete方法是否可以正常执行?

 

2、执行代码后报什么错?


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


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/29 19:17:00 [只看该作者]



Dim str_name As String="王"
Dim str_sign As String="信"
'Dim str_SearchTable As String=args(2)
Dim str_tel As String="15321111111"
Dim str_content As String="上行短信第13遍"
Dim str_status As Boolean=True   '用于判断是否需要接收发送成功的 弹出提醒
str_content=str_sign & "提示您:" & str_content
      


Dim str_cookies As String
Dim user As String = "yc_yy"
  Dim salt As String = "123"
  Dim str_temp As String = "cqq7@X" & salt
  Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_temp,"MD5").ToUpper    '字符串md5化


Dim hc As New HttpClient("http://10.10.10.10:10/session")  '登陆
hc.FormData.Add("user",user)
hc.FormData.Add("salt",salt)
hc.FormData.Add("auth",auth)
Dim ret As String = hc.getData()
Dim jo As JObject= JObject.Parse(ret)

For Each key As String In hc.rCookies.Keys
   'msgbox(key)                   'TWISTED_SESSION
   'msgbox(hc.rCookies(key))      '3f9eeb6d92868f039034f24483a2c52f
   
   str_cookies= hc.rCookies(key)
   msgbox(str_cookies) 
Next

'msgbox(4)
'在提交的时候附带cookies
Dim hc_send As New HttpClient("10.10.10.10:10/message")    '发短信
hc_send.sCookies.Add("TWISTED_SESSION",str_cookies)
hc_send.FormData.Add("desttermid",str_tel)
hc_send.FormData.Add("content",str_content)
hc_send.FormData.Add("mode","2")  '表示需要查收回复
Dim ret_send As String = hc_send.getData()

Dim jo_send As JObject= JObject.Parse(ret_send)
msgbox(jo_send("errorcode").ToString)
msgbox(jo_send("taskid").ToString)


'接收回复
'Dim str_reply As String ="http://10.10.10.10:10/message/taskid/" & 
'Dim hc_send As New HttpClient("10.10.10.10:10/message")    '发短信
'hc_send.sCookies.Add("TWISTED_SESSION",str_cookies)
'hc_send.FormData.Add("desttermid",str_tel)
'hc_send.FormData.Add("content",str_content)
'hc_send.FormData.Add("mode","2")   


'msgbox(5)
 ' 接收发送后的返回信息
Dim dr_receipt As Row = Tables("短信通知回执表").AddNew
 dr_receipt("returnstatus") = jo_send("errorcode")
         
If str_status=True Then   '如果需要弹出提醒则弹,否则不弹
   If jo_send("errorcode") ="0"  Then   '如果返回发送成功信息
      MessageBox.Show("发送成功")
   Else 
      MessageBox.Show("发送失败")
   End If
End If
 dr_receipt("taskID") = jo_send("taskID")
 dr_receipt("回执时间") = Date.Now
 dr_receipt("发送号码") = str_tel
 dr_receipt("发送内容") = str_content
 dr_receipt("姓名")= str_name    '保存发送对象的姓名在通知回执里
 dr_receipt.Save     ' 保存回执


msgbox(str_cookies) 
'查收回复   
Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/message/taskid/" & "41d6d7336c6eaca81a62d2100e4c7")
req.Method = "GET"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
msgbox(str_cookies)
Dim ck As new System.Net.Cookie("TWIST_SESSION", str_cookies)
req.CookieContainer.add(new Uri("http://10.10.10.10:10"), ck)
Dim pos = req.GetResponse()
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)


用上面的代码,依次弹出如下提示,短信是成功收到了的。证明每次的cookies都是一样的
1178c55d833f3a3febb66e8c4223d10f        'cookies
41d6d7847652d5dc1a62d210167d            'taskid
1178c55d833f3a3febb66e8c4223d10f        'cookies
1178c55d833f3a3febb66e8c4223d10f         'cookies
{"errorcode": -20, "result": "\u8bf7\u5148\u767b\u5f55"}




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


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

1、你的delete方法是否可以正常执行?

 

2、执行代码后报什么错?

 

3、细节问题,请自行咨询设备厂家。


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


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/29 21:31:00 [只看该作者]

delete方法也不能执行,我咨询了平台厂家的,他们是正常的呀

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


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

以下是引用ycwk在2018/7/29 21:31:00的发言:
delete方法也不能执行,我咨询了平台厂家的,他们是正常的呀

 

直接叫厂家给你发c#或者vb.net的代码。


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


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/7/30 11:10:00 [只看该作者]

这段代码能用httpclient  实现吗?   get方法的


msgbox(str_cookies) 
'查收回复   
Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/message/taskid/" & "41d6d7336c6eaca81a62d2100e4c7")
req.Method = "GET"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
msgbox(str_cookies)
Dim ck As new System.Net.Cookie("TWIST_SESSION", str_cookies)
req.CookieContainer.add(new Uri("http://10.10.10.10:10"), ck)
Dim pos = req.GetResponse()
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)

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


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

试试这样


Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/message/taskid/" & "41d6d7336c6eaca81a62d2100e4c7")
req.Method = "GET"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
msgbox(str_cookies)
Dim ck As new System.Net.Cookie("TWIST_SESSION", str_cookies)
ck.domain = "10.10.10.10"
req.CookieContainer.add(ck)
Dim pos = req.GetResponse()
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)

 


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


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/8/4 21:19:00 [只看该作者]

delete函数的  demo来了:

   [WebMethod(EnableSession = true, BufferResponse = true, Description = "发短信注销")]
        public string SMSOut()
        {
            if (Session["cookie"] != null)
            {
                cookie = (CookieContainer)Session["cookie"];
            }

            string res = Utily.HttpDelete(cookie);

            string resStr = "";

            if (!string.IsNullOrEmpty(res))
            {
                ResultMsg rm = JsonHelper.DeserializeJsonToObject<ResultMsg>(res);

                string err = rm.errorcode;
                resStr = rm.result;
            }

            return resStr;
        }






        /// GET请求与获取结果  
        /// </summary> 
        public static string HttpDelete(CookieContainer cookie)
        {
            string url = "http://10.10.10.10:10/session";
     
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            
         
            webRequest.Method = "DELETE";
            webRequest.C;
            webRequest.Timeout = 60000;
            webRequest.CookieContainer = cookie;


            //4. 读取服务器的返回信息
            HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string res = sr.ReadToEnd();
            return res;
        }
[此贴子已经被作者于2018/8/4 21:41:31编辑过]

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


加好友 发短信
等级:六尾狐 帖子:1218 积分:8451 威望:0 精华:0 注册:2016/2/2 21:52:00
  发帖心情 Post By:2018/8/4 22:37:00 [只看该作者]

使用下面的代码注销时始终提示 已经登出, 我怀疑是注销时没有成功把cookies传给服务器

Dim str_name As String="王"
Dim str_sign As String="心"
Dim str_tel As String="15311111111"
Dim str_content As String="你有新任务"
Dim str_ReplyMessage As String=""   '用于判断是否需要接收发送成功的 弹出提醒
str_content=str_sign & "提示您:" & str_content
        


Dim str_cookies As String
'Dim cookieCon = new System.Net.CookieContainer


Dim user As String = "yc_yy"
  Dim salt As String = "123"
  Dim str_temp As String = "cqq7@XfW1K4W" & salt
  Dim auth = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_temp,"MD5").ToUpper    '字符串md5化
'msgbox(auth)
'msgbox(3)
Dim hc As New HttpClient("http://10.10.10.10:10/session")  '登陆
hc.FormData.Add("user",user)
hc.FormData.Add("salt",salt)
hc.FormData.Add("auth",auth)
Dim ret As String = hc.getData()
Dim jo As JObject= JObject.Parse(ret)
'msgbox(jo("errorcode").ToString)    '可以正确弹出
'msgbox(jo("result").ToString)     '可以正确弹出
For Each key As String In hc.rCookies.Keys
   msgbox(key)                   'TWISTED_SESSION
   msgbox(hc.rCookies(key))      '3f9eeb6d92868f039034f24483a2c52f
  ' cookieCon.Headers.add(hc.rCookies(key))
   str_cookies=hc.rCookies(key)
Next


Dim wb As New WeUI
Dim req = System.Net.WebRequest.Create("http://10.10.10.10:10/session")
req.Method = "DELETE"
Dim cookieCon = new System.Net.CookieContainer
req.CookieContainer = cookieCon
'Dim ck As new System.Net.Cookie("TWIST_SESSION", str_ )
wb.AppendCookie("TWIST_SESSION",str_cookies) 
req.CookieContainer.add(new Uri("http://10.10.10.10"), wb)
Dim pos = req.GetResponse()
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)




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


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

 

不然,你参考下面

 

http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=54957&authorid=0&page=0&star=2

 

发送登陆的时候也用 System.Net.WebRequest.Create

[此贴子已经被作者于2018/8/6 0:06:28编辑过]

 回到顶部
总数 41 上一页 1 2 3 4 5 下一页