要模拟登录下面的页面,通过账户密码登录。代码如下
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编辑过]
此主题相关图片如下: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编辑过]
需求就是模拟登录,然后给手机号码发信息。模拟登录成功了,发消息不成功。完整代码如下
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编辑过]
这种我也不会,只能自行去分析网页。
可能是需要添加之前登录后的cookie的,试试按1楼的方式加上登录后的cookie信息
服务器登录后会返回一个Cookies名为JSESSIONID。
完整的代码加了这个也没用
hc.sCookies.Add("JSESSIONID",“XXXXXX”)
如何让第2次提交表单的时候默认为在登录的系统内,或者如何提交默认的http事件头
同事说他用java做的,登录后http包会帮忙提交事件头的,他的代码里面就不需要在手动添加cookie了。
java我不懂。但是Foxtable的HttpClient每次调用都是独立的,和之前的调用没有半毛钱的关系,也不会自动提交之前调用的任何东西。