Http Request

Just starting out? Need help? Post your questions and find answers here.
thyr0x1ne
User
User
Posts: 18
Joined: Sat Feb 14, 2004 11:38 pm

Http Request

Post by thyr0x1ne »

Im a totally beginner as i said before ... no Delphi , no C ; only PureBasic discovered a few days ago :

There is my first code :

Code: Select all

OpenConsole()

Structure HTTPReq
   head.s 
   langage.s
   agent.s
   host.s
   conn.s
EndStructure 
  
Global URL$
Global EOL$

URL$ = "http://whois.arin.net" 
EOL$ = Chr(13)+Chr(10)

Procedure DisplayHelp()
    PrintN("* IP Whois v1.0")
    PrintN("* Based on http://whois.arin.net/")
    PrintN("* Usage : whois -s IP")
    Input()
EndProcedure  
 
If InitNetwork() = 0
   PrintN("Erreur Impossible d'initialiser TCP/IP")
EndIf  

Repeat
   param.s = ProgramParameter()
   Select LCase(param)
      Case "-h" : DisplayHelp()
      Case "-s" : ip.s = ProgramParameter()
   EndSelect
Until param = ""

Dim edu.HTTPReq(1)
 
edu(0)\head = "GET http://whois.arin.net/cgi-bin/whois.pl?queryinput="+ip.s
edu(0)\langage = "Accept-Language: en-us"
edu(0)\agent = "User-Agent: Mozilla/??"
edu(0)\host = "Host : whois.arin.net"
edu(0)\conn = "Connection: Close"

com$ = edu(0)\head+EOL$+edu(0)\langage+EOL$+edu(0)\agent+EOL$+edu(0)\host+EOL$+edu(0)\conn 

Whois = OpenNetworkConnection(URL$,80)

event.l = NetworkClientEvent(whois)

;; event give me 2 

PrintN(Str(event.l))

SendNetworkString(Whois,com$) 

WhoisBuffer = AllocateMemory(0, 100)

If ReceiveNetworkData(whois, *WhoisBuffer, 100)
    OpenFile(0,"ip.log")
    PrintN("data : "+PeekS(WhoisBuffer)) 
    CloseFile(0)
EndIf

End

CloseConsole()
All things are fine , i send data , NetworkEvent gives me the reply "2" ( event.l ) but im totally lost in order to retrieve the "real-text" datas in a file or in console ; so thats a bit difficult to be sure my request has a correct form.


Im sure some will laugh seeing :
If ReceiveNetworkData(whois, *WhoisBuffer, 100)
OpenFile(0,"ip.log")
PrintN("data : "+PeekS(WhoisBuffer))
CloseFile(0)
EndIf

but lol , nobody's perfect :)

Thks again for your help
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post by coma »

[edit] deleted
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

Try this:

Code: Select all

*WhoisBuffer = AllocateMemory(0, 100) 

If ReceiveNetworkData(whois, *WhoisBuffer, 100) 
    OpenFile(0,"ip.log") 
    PrintN("data : "+PeekS(*WhoisBuffer)) 
    CloseFile(0) 
EndIf
If you go with Pointers like *WhoisBuffer, then the * is required all the time as it's part of the identifier.

But as long as you're sure there will be only string-data, i.e. no zero-Byte, you could also try this:

Code: Select all

text.s = Space(100)
If ReceiveNetworkData(whois, text, 100) 
    OpenFile(0,"ip.log") 
    PrintN("data : "+text) 
    CloseFile(0) 
EndIf
Both are quick hacks that aren't tested, so don't beat me if they don't function. I have a very good excuse if they don't: I have a headache like hell.

cu
thyr0x1ne
User
User
Posts: 18
Joined: Sat Feb 14, 2004 11:38 pm

Post by thyr0x1ne »

Nope , nothing new ... but you are surely better than me , even with a headache :?

Now have to admit that im wrong in the way i ask the http request ; and i cant use Win API ^^
So maybe if you take a look tomorrow you will find where's my bug


thanks and take care
Post Reply