forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


VDS HTTP project

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript Open Source Projects
View previous topic :: View next topic  
Author Message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Thu Jan 01, 2004 1:48 am    Post subject: VDS HTTP project Reply with quote

Hi all,

I have some code that needs to be worked on, it worked at one point,
but not right. I tried it with more parameters and it didn't work, so it will
have to be developed with the VDS 5 update. It uses VDSINET. I originally
converted it from an IBASIC demo script. I'll include that too so it can be
used for reference.

Code:
title VDS HTTP project
%%UserAgent = "Test"
%%Site = "www.vdsworld.com"
%%Doc = ""


# HINTERNET HttpOpenRequest(
#   HINTERNET hConnect,
#   LPCTSTR lpszVerb,
#   LPCTSTR lpszObjectName,
#   LPCTSTR lpszVersion,
#   LPCTSTR lpszReferer,
#   LPCTSTR* lpszAcceptTypes,
#   DWORD dwFlags,
#   DWORD_PTR dwContext
# );

loadlib wininet.dll

%%HOpen = @lib(WININET,InternetOpenA,INT:,%%UserAgent,0,NIL:,NIL:,0)
%%HConnect = @lib(WININET,InternetConnectA,INT:,%%HOpen,%%Site,80,NIL:,NIL:,3,0,0)
#
#  HINTERNET hInternet,
#  LPCTSTR lpszServerName,
#  INTERNET_PORT nServerPort,
#  LPCTSTR lpszUsername,
#  LPCTSTR lpszPassword,
#  DWORD dwService,
#  DWORD dwFlags,
#  DWORD_PTR dwContext
#
%%HHttp = @lib(WININET,HttpOpenRequestA,INT:,%%HConnect,"GET",%%Doc,NIL:,"",NIL:,$80000000,0,0)
# HINTERNET HttpOpenRequest(
#   HINTERNET hConnect,
#   LPCTSTR lpszVerb,
#   LPCTSTR lpszObjectName,
#   LPCTSTR lpszVersion,
#   LPCTSTR lpszReferer,
#   LPCTSTR* lpszAcceptTypes,
#   DWORD dwFlags,
#   DWORD_PTR dwContext
# );
#

%%HSend = @lib(WININET,HttpSendRequestA,INT:,%%HHttp,NIL:,0,NIL:,0)
# BOOL HttpSendRequest(
#   HINTERNET hRequest,
#   LPCTSTR lpszHeaders,
#   DWORD dwHeadersLength,
#   LPVOID lpOptional,
#   DWORD dwOptionalLength
# );
#
%B = @FILL(255)
%L = @BINARY(DWORD,@LEN(%B))
repeat
%%Read = @lib(WININET,InternetReadFile,BOOL:,%%HHttp,@ADDR("%B"),255,@ADDR("%L"))
until %%Read
# InternetReadFile(hhttp,buffer,255,br)
%A = @lib(WININET,InternetCloseHandle,NIL:,%%HHttp)
%A = @lib(WININET,InternetCloseHandle,NIL:,%%HConnect)
%A = @lib(WININET,InternetCloseHandle,NIL:,%%HOpen)

freelib wininet.dll

# BOOL InternetReadFile(
#  HINTERNET hFile,
#  LPVOID lpBuffer,
#  DWORD dwNumberOfBytesToRead,
#  LPDWORD lpdwNumberOfBytesRead
# );

# hFile
#   [in] Handle returned from a previous call to InternetOpenUrl, FtpOpenFile, GopherOpenFile, or HttpOpenRequest.
# lpBuffer
#   [out] Pointer to a buffer that receives the data.
# dwNumberOfBytesToRead
#   [in] Number of bytes to be read.
# lpdwNumberOfBytesRead
#   [out] Pointer to a variable that receives the number of bytes read. InternetReadFile sets this value to zero before doing any work or error checking.
info @ADJUST(%B)
exit


IBasic Code:

Code:
REM example of how to use the internet functions in wininet.dll
REM the html source of the website is retrieved and displayed
REM in the console window
REM for descriptions of the various functions see http://msdn.microsoft.com

SETID "INTERNET_SERVICE_FTP",1
SETID "INTERNET_SERVICE_GOPHER",2
SETID "INTERNET_SERVICE_HTTP",3

SETID "INTERNET_PRECONFIG",0
SETID "INTERNET_DIRECT",1
SETID "INTERNET_PROXY",3
SETID "INTERNET_FLAG_RELOAD",0x80000000

DECLARE "wininet",InternetOpenA(agent:string,access:int,proxyname:string,proxybypass:string,flags:int),int
DECLARE "wininet",InternetConnectA(session:int,server:string,port:word,username:string,pass:string,service:int,flags:int,context:int),int
DECLARE "wininet",InternetCloseHandle(handle:int),int
DECLARE "wininet",HttpOpenRequestA(session:int,verb:string,name:string,version:pointer,referer:string,types:pointer,flags:int,context:int),int
DECLARE "wininet",HttpSendRequestA(handle:int,headers:pointer,headerlength:int,option:pointer,optionlength:int),intint),int
DECLARE "wininet",InternetReadFile(hfile:int,buffer:string,count:int,bytesread:pointer),int
DECLARE "wininet",InternetQueryDataAvailable(hfile:int,bytesavail:pointer,flags:int,context:int),int

DEF hopen,hconnect,hhttp:int
DEF buffer:STRING
DEF br,avail:int
DEF null:POINTER
REM change the site$ to any site you want.
site$ = "www.google.com"
doc$ = ""
ref$ = "IBasic"
OPENCONSOLE

hopen = InternetOpenA(ref$,@INTERNET_PRECONFIG,"","",0)
IF hopen
   PRINT "Wininet initialized"
   hconnect = InternetConnectA(hopen,site$,80,"","",@INTERNET_SERVICE_HTTP,0,0)
   IF hconnect
      PRINT "Connection established"
      hhttp = HttpOpenRequestA(hconnect,"GET",doc$,null,"",null,@INTERNET_FLAG_RELOAD,0)
      IF hhttp
         IF HttpSendRequestA(hhttp,null,0,null,0)
            PRINT "Request Made"
            DO
               InternetReadFile(hhttp,buffer,255,br)
               buffer = left$(buffer,br)
               IF br THEN PRINT buffer,
               buffer = ""
            UNTIL br = 0
         ENDIF
         InternetCloseHandle(hhttp)
      ENDIF
      InternetCloseHandle(hconnect)
   ENDIF
   InternetCloseHandle(hopen)
ENDIF

PRINT
PRINT "Press any key to close"
DO
UNTIL INKEY$ <> ""
CLOSECONSOLE
               
END

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Fri Jan 02, 2004 5:00 pm    Post subject: Reply with quote

This is what I made some time ago, using the same example... Smile

Code:
#define function,wininet
#define command,wininet

info @wininet(http,get,http://www.google.com/)

exit

rem Info @ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/httpsendrequest.asp

:wininet

if @equal(%1,"http")

  rem Example how to call this function: @wininet(http,get,http://www.google.com/)

  loadlib wininet.dll

  if @equal(%2,"setheader")
    %%HTTP_HEADER = %3
    exit 
    end
 
  rem ---------------- Headers ----------------

  %%Buffer =
  %%INTERNET_SERVICE_FTP = 1
  %%INTERNET_SERVICE_GOPHER = 2
  %%INTERNET_SERVICE_HTTP = 3

  %%INTERNET_PRECONFIG = 0
  %%INTERNET_DIRECT = 1
  %%INTERNET_PROXY = 3
  %%INTERNET_FLAG_RELOAD = $80000000

  rem %%Site = "www.google.com"
  %%Document =
  %%ref = "IBasic"

  if @equal(%2,"GET")
    %%Method = "GET"
    elsif @equal(%2,"POST")
    %%Method = "POST"
    else
    %%Method = %2
    end

  rem Remove the HTTP://, otherwise servers will give an error...

  %%Site = %3
  if @equal(@substr(%%Site,1,7),"HTTP://")
    %%Site = @strdel(%%Site,1,7)
    end

  rem Split the document from the site address, to avoid errors.

  if @unequal(@pos(/,%%Site),0)
    %%Document = @substr(%%Site,@pos(/,%%Site),@len(%%Site))
    %%Site = @strdel(%%Site,@pos(/,%%Site),@len(%%Site))
    end
   
  rem ---------------- Headers ----------------

  %%HandleOpen = @lib(wininet.dll,InternetOpenA,INT:,STR:%%ref,INT:%%INTERNET_PRECONFIG,STR:,STR:,INT:0)
  if @unequal(%%HandleOpen)
    rem Wininet initialized
    %%HandleConnect = @lib(wininet.dll,InternetConnectA,INT:,INT:%%HandleOpen,STR:%%Site,INT:80,STR:,STR:,INT:%%INTERNET_SERVICE_HTTP,INT:0,INT:0)
    if @unequal(%%HandleConnect)
      rem Connection established
      %%HandleHTTP = @lib(wininet.dll,HttpOpenRequestA,INT:,INT:%%HandleConnect,STR:%%Method,STR:%%Document,NIL:,NIL:,NIL:,%%INTERNET_FLAG_RELOAD,0)       
      if @unequal(%%HandleHTTP)
     
      rem --- Add headers here ---
     
      rem Info @ http://msdn.microsoft.com/library/en-us/wininet/wininet/httpaddrequestheaders.asp
      rem        http://beta.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20280311.html
     
      # $10000000 = if not exists yet
      # $80000000 = replace if exists

      %B = %%HTTP_HEADER
      %%TempVar = @lib(wininet.dll,HttpAddRequestHeadersA,INT:,INT:%%HandleHTTP,STR:%B,INT:@len(%B),INT:$80000000$10000000)
     
      rem --- End headers ---
     
        if @unequal(@lib(wininet.dll,HttpSendRequestA,INT:,%%HandleHTTP,NIL:,0,NIL:,0))
          rem Request Made
          repeat
            %x = @binary(dword,0)
            %y = @fill(256,,Z)
            %%TempVar = @lib(wininet.dll,InternetReadFile,INT:,INT:%%HandleHTTP,@addr("%y"),INT:256,@addr("%x"))
            %%Buffer = %%Buffer%y
          until @equal(@val(%x),0)
          else
          rem Request couldn't be made...
          end
       %%TempVar = @lib(wininet.dll,InternetCloseHandle,INT:,%%HandleHTTP)
       else
        rem No handle for the HTTP connection...
        end
      %%TempVar = @lib(wininet.dll,InternetCloseHandle,INT:,%%HandleConnect)
      else
      rem No handle for the connection with the server...
      end
    %%TempVar = @lib(wininet.dll,InternetCloseHandle,INT:,%%HandleOpen)
    else
    rem Connection couldn't be inialized...
    end

  freelib wininet.dll

  exit @trim(%%Buffer)
 
  end
 
exit

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Fri Jan 02, 2004 5:18 pm    Post subject: Reply with quote

Wow nice job Skit!! Very Happy

BTW, will this be able to be used in any computer? Why do I always hear
that WININET is not reliable or something? Confused

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Fri Jan 02, 2004 5:41 pm    Post subject: Reply with quote

I think because there are a number of different versions or something.
But I also think that every PC since Windows 95 or 98 has got the right
DLL... Smile

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Fri Jan 02, 2004 5:54 pm    Post subject: Reply with quote

I hear WINSOCK is supposed to be better but I can't even figure out how
to use that.

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2146
Location: A House

PostPosted: Fri Jan 02, 2004 7:30 pm    Post subject: Reply with quote

Didn't one of the examples with VDS 5 use the winsock???

-Garrett

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
http://www.freewarehome.com <-- Freeware listings since 1996
Back to top
View user's profile Send private message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2146
Location: A House

PostPosted: Fri Jan 02, 2004 7:45 pm    Post subject: Reply with quote

Never mind... It was the ftp example and it uses the wininet.dll also.

-Garrett

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
http://www.freewarehome.com <-- Freeware listings since 1996
Back to top
View user's profile Send private message
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sat Jan 03, 2004 2:06 am    Post subject: Reply with quote

Maybe someone with enough knowledge of winsock could knock together
a quick example for us to build on. Smile

_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sun Mar 28, 2004 3:08 am    Post subject: Reply with quote

Hey guys, Smile

Has anyone tried the wininet HttpQueryInfoA function?

HTTP GET works fine with VDSug.dll, but I'd like to
check filesize to monitor progress (when filesize
info is available). So far I can't retrieve it... Confused

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
GeoTrail
Valued Contributor
Valued Contributor


Joined: 18 Feb 2003
Posts: 572
Location: Bergen, Norway

PostPosted: Fri Nov 26, 2004 11:25 am    Post subject: Reply with quote

I just tried this and it worked just a second ago but now it doesn't work anymore.
Code:
<?php
if (isset($_GET['username'])
{
   echo $_GET['username']."|";
   echo $_SERVER['HTTP_REFERER']."|";
   echo $_SERVER['HTTP_USER_AGENT']."|";
   echo $_SERVER['REMOTE_ADDR']."|";
}
else
{
   echo "No username specified!";
}
?>
Code:
  #define function,wininet
  #define command,wininet

  info Result:@lf()@wininet(http,get,http://www.geotrail-corp.com/test/index.php?username=GeoTrail)

  exit

  rem Info @ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/httpsendrequest.asp

:wininet

  if @equal(%1,"http")

    rem Example how to call this function: @wininet(http,get,http://www.google.com/)

    loadlib wininet.dll

    if @equal(%2,"setheader")
      %%HTTP_HEADER = %3
      exit
    end

    rem ---------------- Headers ----------------

    %%Buffer =
    %%INTERNET_SERVICE_FTP = 1
    %%INTERNET_SERVICE_GOPHER = 2
    %%INTERNET_SERVICE_HTTP = 3

    %%INTERNET_PRECONFIG = 0
    %%INTERNET_DIRECT = 1
    %%INTERNET_PROXY = 3
    %%INTERNET_FLAG_RELOAD = $80000000

    rem %%Site = "www.google.com"
    %%Document =
    %%ref = "IBasic"

    if @equal(%2,"GET")
      %%Method = "GET"
    elsif @equal(%2,"POST")
      %%Method = "POST"
    else
      %%Method = %2
    end

    rem Remove the HTTP://, otherwise servers will give an error...

    %%Site = %3
    if @equal(@substr(%%Site,1,7),"HTTP://")
      %%Site = @strdel(%%Site,1,7)
    end

    rem Split the document from the site address, to avoid errors.

    if @unequal(@pos(/,%%Site),0)
      %%Document = @substr(%%Site,@pos(/,%%Site),@len(%%Site))
      %%Site = @strdel(%%Site,@pos(/,%%Site),@len(%%Site))
    end

    rem ---------------- Headers ----------------

    %%HandleOpen = @lib(wininet.dll,InternetOpenA,INT:,STR:%%ref,INT:%%INTERNET_PRECONFIG,STR:,STR:,INT:0)
    if @unequal(%%HandleOpen)
      rem Wininet initialized
      %%HandleConnect = @lib(wininet.dll,InternetConnectA,INT:,INT:%%HandleOpen,STR:%%Site,INT:80,STR:,STR:,INT:%%INTERNET_SERVICE_HTTP,INT:0,INT:0)
      if @unequal(%%HandleConnect)
        rem Connection established
        %%HandleHTTP = @lib(wininet.dll,HttpOpenRequestA,INT:,INT:%%HandleConnect,STR:%%Method,STR:%%Document,NIL:,NIL:,NIL:,%%INTERNET_FLAG_RELOAD,0)
        if @unequal(%%HandleHTTP)

          rem --- Add headers here ---

          rem Info @ http://msdn.microsoft.com/library/en-us/wininet/wininet/httpaddrequestheaders.asp
          rem        http://beta.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20280311.html

          # $10000000 = if not exists yet
          # $80000000 = replace if exists

          %B = %%HTTP_HEADER
          %%TempVar = @lib(wininet.dll,HttpAddRequestHeadersA,INT:,INT:%%HandleHTTP,STR:%B,INT:@len(%B),INT:$80000000$10000000)

          rem --- End headers ---

          if @unequal(@lib(wininet.dll,HttpSendRequestA,INT:,%%HandleHTTP,NIL:,0,NIL:,0))
            rem Request Made
            repeat
              %x = @binary(dword,0)
              %y = @fill(256,,Z)
              %%TempVar = @lib(wininet.dll,InternetReadFile,INT:,INT:%%HandleHTTP,@addr("%y"),INT:256,@addr("%x"))
              %%Buffer = %%Buffer%y
            until @equal(@val(%x),0)
          else
            rem Request couldn't be made...
          end
          %%TempVar = @lib(wininet.dll,InternetCloseHandle,INT:,%%HandleHTTP)
        else
          rem No handle for the HTTP connection...
        end
        %%TempVar = @lib(wininet.dll,InternetCloseHandle,INT:,%%HandleConnect)
      else
        rem No handle for the connection with the server...
      end
      %%TempVar = @lib(wininet.dll,InternetCloseHandle,INT:,%%HandleOpen)
    else
      rem Connection couldn't be inialized...
    end

    freelib wininet.dll

    exit @trim(%%Buffer)

  end

  exit

Now it doesn't return anything when I do a check for GET on the server.

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Fri Nov 26, 2004 12:18 pm    Post subject: Reply with quote

Perhaps something to do with caching?

I've been using this:

Code:

  #define command,DownloadToFile
 
  %%source = "http://forum.vdsworld.com/viewtopic.php?t=2269"
  %%target = "C:\test.htm"
 
  DownloadToFile %%source,%%target

  exit

:DownloadToFile
  if @equal(%1,)@equal(%2,)
    error 2
  end
  loadlib urlmon
  %z = @lib(urlmon,URLDownloadToFileA,INT:,NIL:,STR:%1,STR:%2,INT:$10,NIL:)
  freelib urlmon
  info %z
  exit


_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript Open Source Projects All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum




Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group