我写了一段代码,到一个网站登录,但登录后再打开里面的链接网页时,有提示要登录,怎么办?

解决方案 »

  1.   

    http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=177681
      

  2.   

    Garfield(猫仔|别忘了结帖,同志) 大侠:您好!谢谢您的解答!现在我还是调试不通,有几个问题,请教:
    '以下代码是我参考“http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=177681”写的,不知错在哪里
    Private Sub Form_Load()With Inet1
       .URL = "http://expert.csdn.net/"
       .UserName = "****"     '请换上一个会员名
       .Password = "******"   '请换上该会员的密码
    End With
    Inet1.Execute , "POST"
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
       Case 12
         'Text1.Text = "HTTP:" + Inet1.GetHeader("HTTP") + vbCrLf _
                   + "Expires:" + Inet1.GetHeader("Expires") + vbCrLf _
                   + "Date:" + Inet1.GetHeader("Date") + vbCrLf _
                   + "Server:" + Inet1.GetHeader("Server") + vbCrLf _
                   + "Set-Cookie:" + Inet1.GetHeader("Set-Cookie") + vbCrLf _
                   + "Content-type:" + Inet1.GetHeader("Content-type") + vbCrLf _
                   + "Content-Length:" + Inet1.GetHeader("Content-Length") + vbCrLf _
                   + "Last-Modified:" + Inet1.GetHeader("Last-Modified")
           Case Else
    End Select
    End Sub    '上面的代码运行的结果如下:
        
        HTTP:
        Expires:
        Date:Wed, 03 Sep 2003 08:01:25 GMT
        Server: Microsoft -IIS / 5#
        Set-Cookie:
        Content-type:text/html
        Content-Length:3647
        Last -Modified:
        请问:(1)为什么上面的HTTP,Expires及Set-Cookie参数是空的呢?
          (2)怎样才能用inet控件(或者是winsock,webbrowser控件)打开“我的专家分”那一页?()
      

  3.   

    1) 登陆的地址错误,应该是 http://expert.csdn.net/member/logon.asp
    2) 用户名密码弄错地方,那个是inet使用代理服务器时的验证密码改为:
    Private Sub Form_Load()
    Inet1.Execute "http://expert.csdn.net/member/logon.asp", "POST", "name=用户&pass=密码"
    end sub
      

  4.   

    谢谢Garfield(猫仔|别忘了结帖,同志) 大侠!请教:(1)我用您的方法,第一次运行时,Set-Cookie参数出现了,但那个HTTP,Expires和Last -Modified参数还是空的。怎么才能看到类似“HTTP /1.0 200 Document follows”的那一行HTTP响应头?以及Expires和Last -Modified参数怎么样才能看到?
    (2)另外,您的那个登录页面"http://expert.csdn.net/member/logon.asp",是怎么找到的?谢谢解答!
      

  5.   

    另:我用下面的代码,先登录,再看http://expert.csdn.net/Expert/member/MyExpertPoint.asp的源代码,与我手工登录再在IE里打开该页面的源代码,有很大的不同:
    Private Sub Form_Load()
    Inet1.Execute "http://expert.csdn.net/member/logon.asp", "POST", "name=名字&pass=密码"Do While Inet1.StillExecuting
       DoEvents
    Loop
    Text1.Text = Inet1.OpenURL("http://expert.csdn.net/Expert/member/MyExpertPoint.asp")End Sub'End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
       Case 12
           Text1.Text = "HTTP:" + Inet1.GetHeader("HTTP") + vbCrLf _
                      + "Expires:" + Inet1.GetHeader("Expires") + vbCrLf _
                      + "Date:" + Inet1.GetHeader("Date") + vbCrLf _
                      + "Server:" + Inet1.GetHeader("Server") + vbCrLf _
                      + "Set-Cookie:" + Inet1.GetHeader("Set-Cookie") + vbCrLf _
                      + "Content-type:" + Inet1.GetHeader("Content-type") + vbCrLf _
                      + "Content-Length:" + Inet1.GetHeader("Content-Length") + vbCrLf _
                      + "Last-Modified:" + Inet1.GetHeader("Last-Modified")               
          MsgBox "1234253425"
       Case Else
    End Select
    End Sub
    这是为什么?请教请教!
      

  6.   

    1) 你直接使用 inet.getheader 查看整个http头,如果没有就是服务器没有给你
    2) 你看登陆的html页面,post form的action属性就是了。
      

  7.   

    Garfield(猫仔|别忘了结帖,同志) 大侠:您好!
    我上面还有一个问题,帮解答一下,好吗?
    其他大侠也请帮帮忙则个。
    谢谢先!---那个问题就是:
    我用下面的代码,先登录,再看http://expert.csdn.net/Expert/member/MyExpertPoint.asp的源代码,与我手工登录再在IE里打开该页面的源代码,有很大的不同:
    Private Sub Form_Load()
    Inet1.Execute "http://expert.csdn.net/member/logon.asp", "POST", "name=名字&pass=密码"Do While Inet1.StillExecuting
       DoEvents
    Loop
    Text1.Text = Inet1.OpenURL("http://expert.csdn.net/Expert/member/MyExpertPoint.asp")End Sub'End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
       Case 12
           Text1.Text = "HTTP:" + Inet1.GetHeader("HTTP") + vbCrLf _
                      + "Expires:" + Inet1.GetHeader("Expires") + vbCrLf _
                      + "Date:" + Inet1.GetHeader("Date") + vbCrLf _
                      + "Server:" + Inet1.GetHeader("Server") + vbCrLf _
                      + "Set-Cookie:" + Inet1.GetHeader("Set-Cookie") + vbCrLf _
                      + "Content-type:" + Inet1.GetHeader("Content-type") + vbCrLf _
                      + "Content-Length:" + Inet1.GetHeader("Content-Length") + vbCrLf _
                      + "Last-Modified:" + Inet1.GetHeader("Last-Modified")               
          MsgBox "1234253425"
       Case Else
    End Select
    End Sub
    这是为什么?请教请教!
      

  8.   

    你直接再用 Execute url,"GET","" , Cookies
    Cookies = 第一次登陆后用 inet1.getheader("Set-Cookie")
      

  9.   

    应该是 Execute url,"GET","" , "Set-Cookie: " & Cookies
      

  10.   

    还是不通。我的代码如下:Option Explicit
    Dim URL As String
    Dim Cookies As StringPrivate Sub Form_Load()
    Inet1.Execute "http://expert.csdn.net/member/logon.asp", "POST", "name=姓名&pass=密码"
    URL = "http://expert.csdn.net/Expert/member/MyExpertPoint.asp"
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
       Case 12
            Cookies = Inet1.GetHeader("Set-Cookie")
       Case Else
    End Select
    Inet2.Execute URL, "GET", "", "Set-Cookie: " & CookiesEnd Sub
    Private Sub Inet2_StateChanged(ByVal State As Integer)
    On Error Resume Next
    Dim stemp As String
    Dim PageCode As String
    Select Case State
      Case 12
        stemp = Inet2.GetChunk(1024)
        Do While stemp <> ""
            PageCode = PageCode + stemp
            stemp = Inet2.GetChunk(1024)
        Loop
         text1.text= PageCode
         End Select
    End Sub在“Inet2.Execute URL, "GET", "", "Set-Cookie: " & Cookies”那一句报错。继续请教!
      

  11.   

    呵呵。。搞糊涂了其实很简单,inet会保存cookies。。不需要像winsock那样代码直接改为:
    Option Explicit
    Dim URL As String
    Dim Cookies As StringPrivate Sub Form_Load()
    Dim stemp As String, pagecode As StringInet1.Execute "http://expert.csdn.net/member/logon.asp?name=用户&pass=密码&from=http://expert.csdn.net/expert", "POST"
        
    Do Until Inet1.StillExecuting = False
        DoEvents
    Loop
    URL = "http://expert.csdn.net/Expert/member/MyExpertPoint.asp"
    Inet1.Execute URL, "GET" ', "", "Cookie: " & Cookies & vbCrLf
    Do Until Inet1.StillExecuting = False
        DoEvents
    Loop
        stemp = Inet1.GetChunk(1024)
        Do While stemp <> ""
            pagecode = pagecode + stemp
            stemp = Inet1.GetChunk(1024)
        Loop
    Text1 = pagecodeEnd Sub
      

  12.   

    还是不通!
    报:
    实时错误:'35756'
    不能完成请求
    还是定位在Inet1.Execute URL, "GET" , "", "Cookie: " & Cookies & vbCrLf上.
    (注:Garfield(猫仔|别忘了结帖,同志) 大侠,您地代码在GET后面多了一个'号吧?)继续请教!
      

  13.   

    注:我的代码如下:
    Option Explicit
    Dim URL As String
    Dim Cookies As String
    Private Sub Form_Load()Inet1.Execute "http://expert.csdn.net/member/logon.asp?name=用户&pass=密码&from=http://expert.csdn.net/expert", "POST"
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
       Case 12
            Cookies = Inet1.GetHeader("Set-Cookie")
       Case Else
       URL = "http://expert.csdn.net/Expert/member/MyExpertPoint.asp"
       Inet2.Execute URL, "GET", "", "Cookie: " & Cookies & vbCrLf
       End Select
    End SubPrivate Sub Inet2_StateChanged(ByVal State As Integer)
    Dim stemp As String, pagecode As String
        stemp = Inet2.GetChunk(1024)
        Do While stemp <> ""
            pagecode = pagecode + stemp
            stemp = Inet2.GetChunk(1024)
        Loop
    Text1.Text = pagecode
    End Sub
      

  14.   

    那个 ' 是我把后面的都注释掉,没用的代码。用一个inet就可以了,不必两个。
    如果两个,不知道两个inet与服务器的asp会话是否一致。你怎么运行不了??
    我完全可以通过。
      

  15.   

    代码通过了。
    谢谢Garfield(猫仔|别忘了结帖,同志) 大侠!
    原来那个'号是您注释掉的,我还以为是您“笔误”呢。sorry!(' 是我把后面的都注释掉,没用的代码。)请教:为什么下面的代码要inet1控件“不忙”时doevents?
    Do Until Inet1.StillExecuting = False
        DoEvents
    Loop
    inet1是异步的,下面的这行代码一开始时不管执行完成与否,都要继续它下面的代码行,对吗?
    Inet1.Execute "http://expert.csdn.net/member/logon.asp?name=用户&pass=密码&from=http://expert.csdn.net/expert", "POST"请教下面代码的奥秘。
    Do Until Inet1.StillExecuting = False
        DoEvents
    Loop
      

  16.   

    是啊,但是要先完成登陆,后面才能取得专家分的页面,否则会取得“没有登陆”的页面。
    如果你inet1.execute后面直接再跟一个inet.execute会说“仍在进行上一个处理”
    所以我用 do/loop 来阻塞主线程。
    1,可以保证已经登陆。
    2,避免inet的错误。
      

  17.   

    还是有个问题要请教:既然“用 do/loop 来阻塞主线程”,为什么是Inet1.StillExecuting = False?而不是Inet1.StillExecuting = true?这个do/loop 循环是不是“当inet1控件不忙时,就是已经做完了上面的execute方法时,执行doevents”这个意思?如果是这个意思,既然inet1都已经不忙了,为什么还要挂起它(doevents)?感觉上应该是Inet1.StillExecuting=true才要do/loop,但这样代码不通。不知为什么要false才行。请教请教!
      

  18.   

    做(do) 
        doevents (响应事件) 
    直到inet的仍在处理=否 (until inet.stillexecuting = false)
    结构上事这样,只是程序语言不是这样写。
       
    看来你最需要搞懂的是英文单词 "Until" 的意思。
      

  19.   

    sorry,原来是我搞错了!我一般都用do while/loop结构,唉!
    给分了!