Problem with http GET command...

Just starting out? Need help? Post your questions and find answers here.
dreamerman
New User
New User
Posts: 3
Joined: Sun Aug 06, 2006 7:34 pm
Location: Poland

Problem with http GET command...

Post by dreamerman »

Hi,
I'm new in PureBasic programming, and I have problem with using http command get. I'm trying in simple way to download a small file - logo of PB of this forum, and I dont recieve the information from server.
This is my code:

Code: Select all


Global EOL$

EOL$ = Chr(13)+Chr(10)


tekst.s
con.l
wynik.l
*bufor=AllocateMemory(1024)
bufor_len.l
otrzymano_len.l
polecenie.s  ;tresc polecenia
polecenieb.b  ;czy bylo polecenie
czs.s


OpenConsole()
InitNetwork()

ConsoleTitle("Klient")



con=OpenNetworkConnection("www.purebasic.fr",80,#PB_Network_TCP)
If con<>NULL
  PrintN("connected")
EndIf

PrintN("prosba o plik")
czs="GET /english/templates/subSilver/images/logo_phpBB.gif HTTP/1.0" + eol$
czl=Len(czs)
PokeS(*bufor,czs,czl,#PB_Ascii)    
   
wynik=SendNetworkData(con,*bufor,czl)
PrintN("wsend: " + Str(wynik))


Repeat

Delay(100)



wynik=NetworkClientEvent(con)

Select wynik
Case #PB_NetworkEvent_Data
PrintN("recieving...")

  otrzymano_len=1024
  *bufor=AllocateMemory(1024)
  ;otrzymywanie
  wynik=ReceiveNetworkData(con,*bufor,otrzymano_len)
  If wynik>1
    tekst=PeekS(*bufor,wynik)

  PrintN("recieved: " + tekst)
;
  EndIf

EndSelect

polecenieb=0
tekst=""
key$=Inkey()
If key$<>""
  
  Print("to exit/quit write 'end': ")
  tekst=Input()

EndIf


Until (tekst="end")

CloseNetworkConnection(con)


CloseConsole()


End
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

Try ...

Code: Select all

EOL$ = Chr(10)+Chr(10) 
;)

Cheers, Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

No, don't switch eol, that part is right.

Replace on line 30:

Code: Select all

czs="GET /english/templates/subSilver/images/logo_phpBB.gif HTTP/1.0" + EOL$
with

Code: Select all

czs="GET /english/templates/subSilver/images/logo_phpBB.gif HTTP/1.0" + EOL$ + EOL$
I love Purebasic.
dreamerman
New User
New User
Posts: 3
Joined: Sun Aug 06, 2006 7:34 pm
Location: Poland

Post by dreamerman »

Ok,
thanks, it's working with these two methods. :D

That is a pity, that there is no multi-platform library for http downloading for PB... Maybe in the future... :roll:
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

dreamerman wrote:That is a pity, that there is no multi-platform library for http downloading for PB... Maybe in the future... :roll:
Would be cool indeed!
I like logic, hence I dislike humans but love computers.
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post by Heathen »

dreamerman wrote:Ok,
thanks, it's working with these two methods. :D

That is a pity, that there is no multi-platform library for http downloading for PB... Maybe in the future... :roll:
The first method may work (chr(10)+chr(10)) but it's not guarunteed on all browsers and header parsers since some rely on the chr(13)s to parse the fields.
I love Purebasic.
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

http://www.purebasic-lounge.de/viewtopi ... e93c#43193

Should work for Linux, Windows, Mac OS
bye,
Daniel
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post by okasvi »

DarkDragon wrote:http://www.purebasic-lounge.de/viewtopi ... e93c#43193

Should work for Linux, Windows, Mac OS
"Should", hmm, I don't see how it works properly for any of them, since it doesn't even support chunked transfer-encoding, which is one of the requirements of HTTP/1.1. And receiving data byte by byte(ReceiveLine()) is just generally _lame_ and should never be done. :?


btw. even thought you send "GET /File HTTP/1.0", your request will be handled as coming from HTTP/1.1 compliant client since you use "Host:" header which isn't supported by HTTP/1.0, and you can check this from response header...
Post Reply