none
[VB 2008.net] 把post的內容加入webclient的header中 RRS feed

  • 問題

  • 我在做一個功能, 其功能是用作發出封包的, 而主要主容希望能跟IE6發出的封包一樣

    但是使用webclient來做

     

    我要做的東西是把在登入時的用戶名稱和密碼一併送出

    在IE裹, 我掛得的封包是..

     

    POST /activities.php?reserveidforcache=ug HTTP/1.1..Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/x-silverlight, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*..Accept-Language: zh-hk..Content-Type: application/x-www-form-urlencoded..Accept-Encoding: gzip, deflate..User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Foxy/1; FunWebProducts; SV1; GTB7.1; Foxy/1; EasyBits GO v1.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1; AskTbMYC-ST/5.12.2.16749)..Host: simrepublic.com..Content-Length: 27..Connection: Keep-Alive..Cache-Control: no-cache....user=XXXX&pass=XXXXXXX

     


    而我使用webclient時 ()代碼如下

     

    Public Shared Function DownloadString(ByVal address As String)
        Dim client As WebClient = New WebClient()
        client.Encoding = Encoding.UTF8
        
        Dim reply As String = client.UploadString(address, "user=" & My.Forms.Form1.login_id.Text & "&pass=" & My.Forms.Form1.login_pw.Text)
        Return reply
      End Function
    

     

    發出的封包就是

    第1個:

     

    POST /activities.php HTTP/1.1..Host: simrepublic.com..Content-Length: 27..Expect: 100-continue..Connection: Keep-Alive....

     

    第2個:

    user=xxxxx&pass=xxxxxx

    分別就是內容跟header分開傳了 (以我的見解)

     

    結果, 網頁在此方法中登入失敗

     

    那我想問的就是, 有法方法可以將 user 和 pass的內容, 加到header裹一起發送嗎?

     

    謝謝

    2011年8月26日 下午 01:51

解答

所有回覆