我正在尝试让我的应用程序在外部网站上执行登录操作。我使用以下代码:
Dim enc As Encoding = Encoding.UTF8
Dim Data As Byte() = Nothing
Dim req As HttpWebRequest
req = CType(Net.WebRequest.Create(URL), Net.HttpWebRequest)
req.Method = method
req.CookieContainer = CookieJar
req.AllowAutoRedirect = False
If method = "POST" Then
req.ContentType = "application/x-www-form-urlencoded"
Data = enc.GetBytes(PostData)
If Data.Length > 0 Then
req.ContentLength = Data.Length
Dim newStream As Stream = req.GetRequestStream()
newStream.Write(Data, 0, Data.Length)
newStream.Flush()
newStream.Close()
End If
End If
Dim Response As Net.HttpWebResponse = CType(req.GetResponse(), Net.HttpWebResponse)
Dim ResponseStream As IO.StreamReader = New IO.StreamReader(Response.GetResponseStream(), enc)
Dim Html As String = ResponseStream.ReadToEnd()
Response.Close()
ResponseStream.Close()
Return Html
什么有效:
- 响应具有所有正确的“Set-Cookie”标头
- 容器保存所有正确的 cookie(总共 5 个)
什么不起作用:
- 容器正在正确检索所有 cookie。但并非所有 cookie 都会随下一个请求一起发送。4 个 cookie 设置正确,但最重要的一个没有发送。
未发送的 cookie 是这个:
Set-Cookie: mpSecurity="ODc2NzM2ODoxMzUODViNTg5OWM1NTNlOWMwYmMxYjUxNWZjYzJjOGQyZGU4MTc2M2M=";Version=1;Path=/;Domain=.xxxxx.nl;Discard
此 cookie 与正确发送的 cookie 之间的唯一区别在于,此 cookie 中包含“Version=1”和“Discard”...
有谁知道为什么所有检索到的 cookie 都被发送,除了上面的那个吗?
任何帮助,将不胜感激!