Page 1 of 1

Problem with http GET command...

Posted: Mon Mar 12, 2007 9:14 pm
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

Posted: Mon Mar 12, 2007 9:29 pm
by Thalius
Try ...

Code: Select all

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

Cheers, Thalius

Posted: Wed Mar 14, 2007 6:13 am
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$

Posted: Fri Mar 16, 2007 10:39 pm
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:

Posted: Sat Mar 17, 2007 12:25 am
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!

Posted: Sat Mar 17, 2007 2:58 am
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.

Posted: Sat Mar 17, 2007 11:01 am
by DarkDragon
http://www.purebasic-lounge.de/viewtopi ... e93c#43193

Should work for Linux, Windows, Mac OS

Posted: Mon Mar 19, 2007 8:23 pm
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...