VB.NET - 传递登录屏幕 [英] VB.NET - Passing the login screen

查看:67
本文介绍了VB.NET - 传递登录屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我点击这个带有插入变量的

登录界面后,我需要从第二页获取一个html源代码:


例如:
https://www.mypage.com/login .php?使用... assword = joepsw


将导致:

https://www.mypage.com/hello.php (这是我需要一个来源的页面

代码来自)

,它不能直接点击....


所以,只是解释一下......如果我点击第一个在浏览器中的网址

将我登录到另一个页面,这是我需要获取html

来源的页面。


我写了这段代码:


Dim finalurl As String =

" https://www.mypage.com/login.php?username = joe& ;密码= joepsw"


Dim webreq As System.Net.WebRequest =

System.Net.WebRequest.Create(finalurl)


Dim webres As System.Net.WebResponse = webreq.GetResponse()

Dim enc As System.Text.Encoding = _

System.Text.Encoding.GetEncoding(" latin1")

Dim st As System.IO.Stream = webres.GetResponseStream( )

Dim sr As New System.IO.StreamReader(st,enc)

Dim html As String = sr.ReadToEnd()


RichTextBox1.Text = html

sr.Close()


所以它应该登录并获取代码,但这不会发生。

它将获得第一个登录页面的源代码,而不是第二个

的源代码。


为什么会发生这种情况。太快了吗?是不是发布了用户名和密码的变量




如果是这种情况,我怎么能先将用户名和密码发布到

php页面然后获取结果源代码?


非常感谢。


Martin

I need to grab a html source code from the second page after I hit this
login screen with inserted variables:

example:
https://www.mypage.com/login.php?use...assword=joepsw

will lead to:

https://www.mypage.com/hello.php (this is the page I need a source
code from)
, it cannot be hit directly....

So, just to explain it more... If I hit the first url in browser it
logs me into another page and that is the page I need to get the html
source from.

I wrote this code:

Dim finalurl As String =
"https://www.mypage.com/login.php?username=joe&password=joepsw"

Dim webreq As System.Net.WebRequest =
System.Net.WebRequest.Create(finalurl)

Dim webres As System.Net.WebResponse = webreq.GetResponse()
Dim enc As System.Text.Encoding = _
System.Text.Encoding.GetEncoding("latin1")
Dim st As System.IO.Stream = webres.GetResponseStream()
Dim sr As New System.IO.StreamReader(st, enc)
Dim html As String = sr.ReadToEnd()

RichTextBox1.Text = html
sr.Close()

So it should log me in and get the code, but this is not happening.
It will get the source code of the first login page, not the second
one.

Why is it happening. Is it too fast? Is it not posting the variables
for username and password?

If that is the case, how can I first post the username and password to
php page and then grab a resulting source code?

Thanks a lot.

Martin

推荐答案

所以我试着再玩它并写下这个....



尝试


Dim req As System.Net.HttpWebRequest

Dim res As System.Net.HttpWebResponse

Dim sr As System .IO.StreamReader

Dim s As System.IO.Stream

Dim b As Byte()


将myPostData调暗为字符串=" username = joe& password = joepsw"

Dim myPostURL As String =

" http://www.mywebsite.com/login.php"


req = System.Net.WebRequest.Create(myPostURL)


b = System.Text.Encoding.ASCII.GetBytes(myPostData)


req.Method =" post&q uot;

req.ContentType =" application / x-www-form-urlencoded"

req.ContentLength = b.Length


''发送数据

s = req.GetRequestStream()

s.Write(b,0,b.Length)

s.Close()

res = req.GetResponse()

sr =新的System.IO.StreamReader(res.GetResponseStream())

RichTextBox1.Text = sr.ReadToEnd()


sr.Close()

res.Close()


Catch ex As Exception

MessageBox.Show(ex.ToString)


结束尝试


这也不行。

我不能通过第一个屏幕,它总是显示我(在richtextbox中)

的源代码登录界面。


有人可以帮助我,我怎么能从第二页获得代码???


Martin。

So I tried to play with it little more and wrote this....


Try

Dim req As System.Net.HttpWebRequest
Dim res As System.Net.HttpWebResponse
Dim sr As System.IO.StreamReader
Dim s As System.IO.Stream
Dim b As Byte()

Dim myPostData As String = "username=joe&password=joepsw"
Dim myPostURL As String =
"http://www.mywebsite.com/login.php"

req = System.Net.WebRequest.Create(myPostURL)

b = System.Text.Encoding.ASCII.GetBytes(myPostData)

req.Method = "post"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = b.Length

''send the data
s = req.GetRequestStream()
s.Write(b, 0, b.Length)
s.Close()
res = req.GetResponse()

sr = New System.IO.StreamReader(res.GetResponseStream())
RichTextBox1.Text = sr.ReadToEnd()

sr.Close()
res.Close()

Catch ex As Exception
MessageBox.Show(ex.ToString)

End Try

This doesn''t work either.
I can''t get pass by first screen, it always shows me (in richtextbox)
the source code of the login screen.

Can someone help me, how I can get the code from the second page???

Martin.


有人可以帮忙吗?

Can anyone help, please?


Martin,

我哈d做类似的事情,并发现以下

工具非常宝贵 - 来自 www的HTTP标题.blunck.info 。它可以让你看到发送到服务器的确切内容。


我还发现在两次https请求之后,无论如何

我更改了代码,CLR会抛出异常。所以我用
使用了IPWorks控件。他们相当不错,虽然我认为帮助有点微不足道。 (MethodX - 执行

方法X.那种完全没用的东西。)他们有很好的简单支持证书,这很简单

我自己,非常方便:-)

Neil
Martin,

I had to do something similar, and found the following
tool invaluable - ieHTTPHeaders from www.blunck.info. It
lets you see exactly what is being sent to the server.

I also found that after two https requests, no matter how
I changed the code, the CLR would throw an exception. so I
used the IPWorks controls. They''re pretty good, although I
thought the help was a bit minimal. (MethodX - performs
Method X. That sort of utterly useless stuff.) They had
good simple support for certificates, which, being simple
myself, was very handy :-)

Neil
-----原帖-----
所以我试着用它多玩一下并写下来....

尝试

Dim req As System.Net.HttpWebRequest
Dim res As System.Net.HttpWebResponse
Dim sr As System.IO.StreamReader
Dim s As System.IO.Stream
Dim b As Byte()

昏暗myPostData As String
=" username = joe& password = joepsw" Dim myPostURL As String =
" http://www.mywebsite.com/login.php"

req = System.Net.WebRequest.Create(myPostURL)

b = System.Text.Encoding.ASCII.GetBytes
(myPostData)
req.Method =" post"
req.ContentType =" application / x-www-form -
urlencoded" req.ContentLength = b.Length

''发送数据
s = req.GetRequestStream()
s.Write(b,0,b.Length)
s.Close()
res = req.GetResponse()
sr =新的System.IO.StreamReader
(res.GetResponseStream())RichTextBox1.Text = sr。 ReadToEnd()

sr.Close()
res.Close()

Catch ex As Exception
MessageBox.Show(ex.ToString)<结束尝试

这也不行。
我不能通过第一个屏幕,它总是显示我(
) richtextbox)登录界面的源代码。

有人可以帮助我,我怎样才能从
第二页获得代码???
Martin。

-----Original Message-----
So I tried to play with it little more and wrote this....


Try

Dim req As System.Net.HttpWebRequest
Dim res As System.Net.HttpWebResponse
Dim sr As System.IO.StreamReader
Dim s As System.IO.Stream
Dim b As Byte()

Dim myPostData As String = "username=joe&password=joepsw" Dim myPostURL As String =
"http://www.mywebsite.com/login.php"

req = System.Net.WebRequest.Create(myPostURL)

b = System.Text.Encoding.ASCII.GetBytes (myPostData)
req.Method = "post"
req.ContentType = "application/x-www-form- urlencoded" req.ContentLength = b.Length

''send the data
s = req.GetRequestStream()
s.Write(b, 0, b.Length)
s.Close()
res = req.GetResponse()

sr = New System.IO.StreamReader (res.GetResponseStream()) RichTextBox1.Text = sr.ReadToEnd()

sr.Close()
res.Close()

Catch ex As Exception
MessageBox.Show(ex.ToString)

End Try

This doesn''t work either.
I can''t get pass by first screen, it always shows me (in richtextbox)the source code of the login screen.

Can someone help me, how I can get the code from the second page???
Martin.

.



这篇关于VB.NET - 传递登录屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆