Failed HTTP GET

Community Forums/General Help/Failed HTTP GET

Sauer(Posted 2009) [#1]
Hi everyone,
I'm currently trying to wrap my head around some of the HTTP methods to write an online high score table with Blitz and PHP. Here's the general plan:

1. Scores sent to the script using HTTP POST
2. Scores managed by script, update data base, echoed to screen
3. HTTP GET the page with the echoed data
4. Parse and display in program

The PHP script is working as planned, but I'm having issues getting the Blitz program to access the script. My problem is I can't seem to perform a GET on my script, currently located at home.fuse.net/csauer_9781/test.php. I used Mark's example in the code archives just to be sure it wasn't a code issue. Also, I can't ping that location or get any IP info.

Is this because it doesn't have a domain name associated with it? Any advice?

Thanks,


D4NM4N(Posted 2009) [#2]
I can ping it:


dan@Babylon:~$
dan@Babylon:~$ ping home.fuse.net
PING php.fuse.net (66.161.131.50) 56(84) bytes of data.
64 bytes from php.fuse.net (66.161.131.50): icmp_seq=1 ttl=52 time=122 ms
64 bytes from php.fuse.net (66.161.131.50): icmp_seq=2 ttl=52 time=122 ms
64 bytes from php.fuse.net (66.161.131.50): icmp_seq=3 ttl=52 time=122 ms
64 bytes from php.fuse.net (66.161.131.50): icmp_seq=4 ttl=52 time=121 ms
^C
--- php.fuse.net ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 121.203/122.113/122.476/0.679 ms
dan@Babylon:~$




Sauer(Posted 2009) [#3]
Ok I just tried pinging it, and got it to work, however I didn't receive any of the packets.

So I'm guessing the problem was that I was trying to ping the file itself, which has no IP of its own. Makes sense.

So how would I access the contents generated by the PHP script if I cannot preform a GET on the file?

Thanks,


Brucey(Posted 2009) [#4]
This works for me :
SuperStrict

Framework BaH.libcurl
Import BRL.StandardIO

Local curl:TCurlEasy = TCurlEasy.Create()

curl.setOptInt(CURLOPT_FOLLOWLOCATION, 1)
curl.setWriteString()

curl.setOptString(CURLOPT_URL, "home.fuse.net/csauer_9781/test.php")

curl.perform()
curl.cleanup()

Print curl.toString()


Executing:untitled5
Names Scores<br>Brian
 501
<br>Brian
 501
<br>Brian
 501
<br>Brian
 501
<br>Brian
 501
<br>Brian
 501
<br> <br>

Process complete


:-)


Sauer(Posted 2009) [#5]
Too bad I don't own and know little about BMax :)

Is the executing the script within (for lack of a better word) BMax?

And what could I do with B+?


Brucey(Posted 2009) [#6]
Is the executing the script within (for lack of a better word) BMax?

It's a C library for URL data transfers (like HTTP and FTP), which is compiled into the BlitzMax application.

And what could I do with B+?

I imagine you should be able to do it via raw TCP calls too - but of course then you run into some of the problems you have done. I'm surprised the example from the code archives isn't working for you though.

That's why I prefer 3rd-party libraries written by people who know what they're doing - so that I don't need to know :-)


Sauer(Posted 2009) [#7]
written by people who know what they're doing

I believe Mark Sibly wrote that example :)

I guess if what you were using is a C library then theoretically I could use it with B+ using DLL's, right?


Brucey(Posted 2009) [#8]
I guess if what you were using is a C library then theoretically I could use it with B+ using DLL's, right?

I believe so.
I wouldn't know where to start with that in BlitzPlus though... but I'm sure there are plenty of people around here who know how to wrap a third party library for it.


Sauer(Posted 2009) [#9]
There was someone on here that made a game in B3D (I think) where you shot birds, and it was really gory (yet fun) and they had an online score table. I guess I should ask them.

Now to find out who that was...


Sauer(Posted 2009) [#10]
I remember now, it was Devil's Child "Bloody Mess 2nd Shot". I re-read the thread and he mentioned something about "passing a video via URL" which would suggest he's using a similar method that I'm trying to do.

He doesn't seem to be around much though... but at least I know it's possible.

I wonder how he got his data. His comes from http://www.dev-ch.de/server/bm2/viewhigh.php


D4NM4N(Posted 2009) [#11]
I can "wget" it too.

dan@Babylon:~$ 
dan@Babylon:~$ 
dan@Babylon:~$ wget home.fuse.net/csauer_9781/test.php
--2009-10-25 21:52:53--  http://home.fuse.net/csauer_9781/test.php
Resolving home.fuse.net... 66.161.131.50
Connecting to home.fuse.net|66.161.131.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 111 [text/html]
Saving to: `test.php.3'

100%[===============================================================================>] 111         --.-K/s   in 0s      

2009-10-25 21:52:54 (11.7 MB/s) - `test.php.3' saved [111/111]

dan@Babylon:~$ cat test.php
Names Scores<br>Brian
 501
<br>Brian
 501
<br>Brian
 501
<br>Brian
 501
<br>Brian
 501
<br>Brian
 501
<br> <br>dan@Babylon:~$ 



I think your problem lies with whatever you are trying to do in your code rather than the server, because if a basic wget can fetch and save the data then there lies not the problem.
Also, what about firewalls? Perhaps the program is blocked from downloading it.


Sauer(Posted 2009) [#12]
Firewall turned off, still fails to connect from Blitz.

Here's the code I'm using, from marksibly's code archive entry:

www=OpenTCPStream( "http://home.fuse.net/csauer_9781/test.php",80 )
If Not www RuntimeError "Failed to connect"
WriteLine www,"GET / HTTP/1.1"
WriteLine www,"Host: www.yahoo.com"
WriteLine www,"User-Agent: BlitzBrowser"
WriteLine www,"Accept: */*"
WriteLine www,""
While Not Eof(www)
    Print "RECV: " + ReadLine(www)
Wend
CloseTCPStream www


It will work when I just try to get the server, home.fuse.net, but how do I access the file itself?


BlitzSupport(Posted 2009) [#13]
You're basically making the request incorrectly. You pass the host name to OpenTCPStream (no "http://" or filename), write the host name in the Host: field (you've stuck Yahoo in there for some reason!) and pass the filename (with starting "/") in the GET field. (Passing just "/" asks for the default file, usually "index.html" or similar.) This works for me:

www=OpenTCPStream( "home.fuse.net",80 )
If Not www RuntimeError "Failed to connect"
WriteLine www,"GET /csauer_9781/test.php HTTP/1.1"
WriteLine www,"Host: home.fuse.net"
WriteLine www,"User-Agent: BlitzBrowser"
WriteLine www,"Accept: */*"
WriteLine www,""
While Not Eof(www)
    Print "RECV: " + ReadLine(www)
Wend
CloseTCPStream www

MouseWait


You might also find this of interest, unless you just want the very basics as above:

BlitzGet Deluxe


Sauer(Posted 2009) [#14]
Hey thanks BlitzSupport, I figured I was just misunderstanding something. Makes sense now; connect to the server (home.fuse.net) with a TCP stream, and call a GET to the path of the file.

Thanks again, should have it all together now. I'll take a look at BlitzGet Deluxe too.