Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共11 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:模拟登录web

1楼
zhenghangbo 发表于:2023/9/12 14:32:00
要模拟登录下面的页面,通过账户密码登录。代码如下

Dim hc1 As New HttpClient("http://xxx.xxx.xxx.xx/login")
hc1.sCookies.Add("operatorCode","xxx")
hc1.sCookies.Add("password","xxxx")
hc1.sCookies.Add("submit", "xxxx")
hc1.sCookies.Add("userType", "")
If hc1.rCookies.ContainsKey("error") Then
    MessageBox.show(hc1.RCookies("error"), "错误",  MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
    MessageBox.Show(hc1.RCookies.tostring)
    
End If
不管账户密码填写了什么,都返回如下数据。像这样的网站应该如何模拟登录

图片点击可在新窗口打开查看此主题相关图片如下:1694500297191(1).jpg
图片点击可在新窗口打开查看


图片点击可在新窗口打开查看此主题相关图片如下:1694500715761.jpg
图片点击可在新窗口打开查看


[此贴子已经被作者于2023/9/12 14:39:40编辑过]
2楼
有点蓝 发表于:2023/9/12 15:02:00
模拟表单:http://www.foxtable.com/mobilehelp/topics/0159.htm
3楼
zhenghangbo 发表于:2023/9/12 15:15:00
可以登录了
4楼
zhenghangbo 发表于:2023/9/12 15:37:00

此主题相关图片如下:1694503998518.jpg
按此在新窗口浏览图片

登录成功后要提交上面的表单,代码如下
Dim hc As New HttpClient("http://xxx.xxx.xxx.xxx/attemper")
        hc.FormData.Add("act", "add")
        hc.FormData.Add("actionid", "SMToSendAction")
        hc.FormData.Add("counter", "296")
         hc.FormData.Add("counter", "30")   (很奇怪要上传2个counter
        hc.FormData.Add("curPage", "null")
        hc.FormData.Add("messageType", "1")
        hc.FormData.Add("method", "")
        hc.FormData.Add("mobile", "")
        hc.FormData.Add("msgContent","123")
        hc.FormData.Add("msgContentWap", "")
        hc.FormData.Add("myFlag", "prompt")
        hc.FormData.Add("needName", "0")
        hc.FormData.Add("nextJsp", "")
        hc.FormData.Add("now", "now")
        hc.FormData.Add("orgAddr", "1065752531750000")
        hc.FormData.Add("receiverList", "7137XXXX747")
        hc.FormData.Add("receivers", "713615810260")
        hc.FormData.Add("reply", "0")
        hc.FormData.Add("report", "0")
        hc.FormData.Add("smSendSingle", "true")
        hc.FormData.Add("sOnDay", "")
        hc.FormData.Add("sSendTime", "1458438655128")
        hc.FormData.Add("urlAddress", "")
        Dim ret1 As String = hc.getData()
        If hc.rCookies.ContainsKey("error") Then
            MessageBox.Show(hc.rCookies("error"), "提示", MessageBoxButtons.OK ,MessageBoxIcon.Warning)
        Else
            MessageBox.Show(ret)
        End If
返回如下数据,返回的数据是不正确的。

此主题相关图片如下:1694504087578.jpg
按此在新窗口浏览图片

正确的响应如下图

此主题相关图片如下:1694504209928.jpg
按此在新窗口浏览图片


[此贴子已经被作者于2023/9/12 15:49:52编辑过]
5楼
zhenghangbo 发表于:2023/9/12 15:49:00
需求就是模拟登录,然后给手机号码发信息。模拟登录成功了,发消息不成功。
完整代码如下
Dim hc1 As New HttpClient("http://xxx.xxx.xxx/operatorlogin")
hc1.FormData.Add("operatorCode", "xxx")
hc1.FormData.Add("password", "xxxx")
hc1.FormData.Add("submit", "xxxxx")
hc1.FormData.Add("userType", "")
Dim ret As String = hc1.getData()
If hc1.rCookies.ContainsKey("error") Then
    MessageBox.Show(hc1.rCookies("error"), "提示", MessageBoxButtons.OK ,MessageBoxIcon.Warning)
Else
    If hc1.ResponseHeaders("Content-Length")=xxx Then    ‘有该返回值说明登录成功
        
        Dim hc As New HttpClient("http://xxx.xxx.xxx.xxx/attemper")
        hc.FormData.Add("act", "add")
        hc.FormData.Add("actionid", "SMToSendAction")
       ' hc.FormData.Add("counter", "297")
        hc.FormData.Add("counter", "30")
        hc.FormData.Add("curPage", "null")
        hc.FormData.Add("messageType", "1")
        hc.FormData.Add("method", "")
        hc.FormData.Add("mobile", "")
        hc.FormData.Add("msgContent","123")
        hc.FormData.Add("msgContentWap", "")
        hc.FormData.Add("myFlag", "prompt")
        hc.FormData.Add("needName", "0")
        hc.FormData.Add("nextJsp", "")
        hc.FormData.Add("now", "now")
        hc.FormData.Add("orgAddr", "1065752531750000")
        hc.FormData.Add("receiverList", "713xxxxx747")
        hc.FormData.Add("receivers", "713xxxxxx747")
        hc.FormData.Add("reply", "0")
        hc.FormData.Add("report", "0")
        hc.FormData.Add("smSendSingle", "true")
        hc.FormData.Add("sOnDay", "")
        hc.FormData.Add("sSendTime", "1458438655128")
        hc.FormData.Add("urlAddress", "")
        Dim ret1 As String = hc.getData()
        If hc.rCookies.ContainsKey("error") Then
            MessageBox.Show(hc.rCookies("error"), "提示", MessageBoxButtons.OK ,MessageBoxIcon.Warning)
        Else
OutPut.Show("内容类型:" & hc.ResponseContentType)
OutPut.Show("状态码:" & hc.StatusCode)
            MessageBox.Show(ret)
            'For Each key As String  In hc.ResponseHeaders.Keys  '显示服务器返回的头部信息
            'OutPut.Show(Key & ":" & hc.ResponseHeaders(key))
            'Next
        End If
    Else
        MessageBox.Show("连接错误")
    End If
End If

[此贴子已经被作者于2023/9/12 15:50:28编辑过]
6楼
有点蓝 发表于:2023/9/12 16:21:00
这种我也不会,只能自行去分析网页。

可能是需要添加之前登录后的cookie的,试试按1楼的方式加上登录后的cookie信息
7楼
zhenghangbo 发表于:2023/9/12 16:21:00
服务器登录后会返回一个Cookies名为JSESSIONID。

完整的代码加了这个也没用
hc.sCookies.Add("JSESSIONID",“XXXXXX”)

如何让第2次提交表单的时候默认为在登录的系统内,或者如何提交默认的http事件头

8楼
有点蓝 发表于:2023/9/12 16:24:00
头部信息参考:http://www.foxtable.com/mobilehelp/topics/3279.htm
9楼
zhenghangbo 发表于:2023/9/12 16:24:00
同事说他用java做的,登录后http包会帮忙提交事件头的,他的代码里面就不需要在手动添加cookie了。
10楼
有点蓝 发表于:2023/9/12 16:27:00
java我不懂。但是Foxtable的HttpClient每次调用都是独立的,和之前的调用没有半毛钱的关系,也不会自动提交之前调用的任何东西。
共11 条记录, 每页显示 10 条, 页签: [1] [2]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03125 s, 2 queries.