Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default MSXML.DLL HTTP getAllResponseHeaders setRequestHeader "Cookie"

parsing up cookies / MSXML.XMLHTTP4.0 / setRequestHeader "Cookie" /
getAllResponseHeaders / HTTP / MSXML.DLL

Everyone must run into this problem - logging in to a web site,
authenticating, getting the session information from the server in assorted
session and persistent cookies and then subsequently sending all the proper
cookies on with subsequent HTTP requests.

I'm NOT opting for WINHTTP5.DLL (Microsoft WinHTTP Services) because I want
to be sure a wide range of windows users can use the code. Trying NOT to use
shdocvw.dll (Internet Explorer) either because it can be very slow with all
the JavaScript, pictures and pixel rendering. All I'm interested in on
subsequent "GET"s are the raw HTTP response text streams.

Sample code below, (Through fetching and parsing the cookies) -- very rough,
not robust.

Couple of questions:

1. Do I ever need to worry about "Set-Cookie2:" ?
2. When I make a subsequent HTTP "GET" request, for instance to
"http://finance.yahoo.com," do I need to include all cookies for BOTH:
.finance.yahoo.com AND
.yahoo.com ?
3. Are cookies always delimited with "; " or sometimes no white space ";"
4. Anyone have any better ideas for how to parse up the "Set-Cookie: "
lines? I feel like an amateur here. Every browser does it with speed and
grace - I'm a neophyte in parsing 101, especially with optional and random
placed arguments.
5. Any tips on error trapping MSXML.DLL, timing it out, etc., so Excel won't
hang if the Internet or the web site go down.
6. Any tips on spitting the cookies back at the server using MSXML.DLL
SetRequestHeader? Can multiple cookies be set at one time. Any "got-yas"?

All very much appreciated!


Rick


ITSdoc stands for Investment and Trading Systems Documentation - the free
encyclopedia of documentation for coders.
http://ITSdoc.org



Sub test()
Dim sHeader As String
sHeader = fetchHeader("http://finance.yahoo.com")
Debug.Print parseCookies(sHeader)
End Sub

Function fetchHeader(sURL As String) As String
' returns an HTTP response header after going to sURL
' need a reference to MSXML.DLL

Dim xmlhttp As Object
Set xmlhttp = CreateObject("MSXML2.Serverxmlhttp.4.0")

With xmlhttp
.Open "GET", sURL, False
.send
While .readyState < 4: .waitForResponse 1000: Wend
fetchHeader = .getAllResponseHeaders()
End With
End Function
Function parseCookies(sHeaderString As String) As String
'You give it a HTTP header string and it chops out all the cookies

Dim i As Integer
Dim j As Integer
Dim aHeaderLine() As String
Dim aCookies() As String
Dim aCookieParts() As String
Dim cookieTray As String

aHeaderLine() = Split(sHeaderString, Chr(13) & Chr(10))
For i = 0 To UBound(aHeaderLine())
If Left(aHeaderLine(i), 12) = "Set-Cookie: " Then 'we have a cookie
' anyone find any "Set-Cookie2: " out there???
aCookieParts() = Split(Mid(aHeaderLine(i), 13), "; ") 'is the whitespace
always there?
cookieTray = cookieTray & aCookieParts(0) & vbTab
For j = 0 To UBound(aCookieParts())
If Left(aCookieParts(j), 7) = "domain=" Then 'got the domain
cookieTray = cookieTray & Mid(aCookieParts(j), 8) & vbCrLf
End If
Next
End If
Next
parseCookies = cookieTray
End Function

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" Luc[_3_] Excel Programming 2 September 28th 05 08:37 PM


All times are GMT +1. The time now is 04:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"