Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

InternetOpenUrl and Cookies...Please Help!

241 views
Skip to first unread message

x

unread,
Feb 22, 2001, 7:02:09 PM2/22/01
to
I have an ASP page that is essentially a url cloaking device. What is does
is to take the calling URL and replace part of it with a new domain name and
pass this url string to a .DLL that uses WinInet to grab the page and return
it as a string to the calling ASP page that in turn return it to the client.
This make shte client think that the page came form our domain, we need this
because of browser security limitations. Here is the problem, some of the
pages use cookies, and I can read the cookies in the ASP page and send them
to the DLL but the InternetOpenUrl(lngHandle1, strUrl, strCookie, lngCookie,
INTERNET_FLAG_RAW_DATA, 0) method doesn't like having a value for the
lpszHeaders(strCookie) and dwHeadersLength(lngCookie) values. Looking
around on the net I can find no examples where people are actually using
these values(always NULL). I've heard that WinInet automatically takes care
of the Cookie values, could someone give me an idea on how to make this
work. I'm attaching the code from the ASP page and the DLL so you can see
what I'm doing.

Thanks
Leon


Runs on Windows 2000 Server

ASP:
<%@ Language="VBSCript" %>
<% Option Explicit %>
<% Response.Buffer = true %>
<%
Dim strInUrl, strPage, objInet, strInQuery, strInCookie

On Error Resume Next
'response.write Request.ServerVariables("ALL_HTTP")
'response.end
strInUrl = Request.ServerVariables("URL")

strInQuery = Request.ServerVariables("QUERY_STRING")
strInCookie = Request.ServerVariables("HTTP_COOKIE")

strInUrl = lcase(strInUrl)
strInUrl = replace(strInUrl,"/devportal/rlocator","")
strInUrl = "http://newServerName" & strInUrl & "?" & strInQuery


Set objInet = Server.CreateObject ("Wrapper.GetPage")
If Err.Number <> 0 Then
Set objInet = nothing
Response.Write ("Error while processing the request")

Response.End
End If

strPage = objInet.DownloadPage(CStr(strInUrl), CStr(strInCookie))
Set objInet = nothing

' *** Do something with the page downloaded
Response.Write strPage

%>
DLL:
Option Explicit

Dim strUrl As String
'Dim strCookie As String
Dim intPort As Integer
Const intBufSize = 3000

Public Function DownloadPage(strUrl As String, strCookie As String) As
String
Dim strBuffer As String * 1000
Dim lngHandle1 As Long
Dim lngHandle2 As Long
Dim intRetVal As Long
Dim intRetSize As Long
Dim strOut As String
Dim lngCookie As Long


DoEvents

lngCookie = Len(strCookie)
lngHandle1 = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, "",
"", 0)
lngHandle2 = InternetOpenUrl(lngHandle1, strUrl, strCookie, lngCookie,
INTERNET_FLAG_RAW_DATA, 0)

Do While True
DoEvents

strBuffer = Space(1000)

intRetVal = InternetReadFile(lngHandle2, strBuffer, 1000,
intRetSize)
If intRetSize = 0 Then
Exit Do
End If

strOut = strOut & strBuffer
Loop

InternetCloseHandle (lngHandle2)
InternetCloseHandle (lngHandle1)

DownloadPage = strOut
End Function

Ozgur Huseyinoglu

unread,
Feb 22, 2001, 11:48:33 PM2/22/01
to

Have you tried using the "INTERNET_FLAG_NO_COOKIES" flag in addition to the
"raw data" flag? I believe if you want to handle cookies without WinInet
interference, you need to use this flag, and a correct syntax for headers.
Here's what MSDN says for this flag:

<<INTERNET_FLAG_NO_COOKIES
Does not automatically add cookie headers to requests, and does not
automatically add returned cookies to the cookie database. This flag can be
used by HttpOpenRequest and InternetOpenUrl (for HTTP requests).>>

I hope that helps,

Ozgur

x <x...@x.com> wrote in message news:9749cf$nkb$1...@bob.news.rcn.net...

0 new messages