
What is raw http Request ? The problem when beginning with high-level language like C#, Java or PHP is that people may have never known how simple the underground is in reality. So here’s a short introduction:
Back in the old days of the Internet (see history), there was a very simple http protocol (known later as HTTP/0.9) where a client could send a command to the server to get an HTML page like this:
GET /welcome.html
and the server would return the content of the page. There was no other method than GET so get is really the basics of http protocol. Since http has been upgraded to HTTP/1.1 but for our first lesson on raw http request, we will stick to the GET Request.
You can of course send that kind of request using Telnet (Linux Power Users should know how to, usually less geeky Windows Users - as myself
- can read a very good tutorial here).
Here’s how to do it in Rebol (I have simplified the original script found on Rebolforces). For the fun, we’re going to request Google’s “I’m Feeling Lucky Page”. Launch Rebol Console and copy and paste the code below:
search-string: "rebol tutorial"
server-response: copy {}
do http://reboltutorial.com/source/encode-url.r
server-port: open tcp://www.google.com:80
url-request: rejoin [
{GET /search?q=} encode-url lowercase copy search-string
{&btnI=I'm+Feeling+Lucky HTTP/1.1} newline
{host: www.google.com} newline
{connection: close} newline newline
]
insert server-port url-request
while [
buffer: copy server-port
][
append server-response buffer
]
close server-port
This script is easy to understand if you have read previous lesson on TCP/IP Client and Server (if not go here).
You can look at variables contents by typing in Rebol Console
probe url-request
probe server-response
write %temp.html server-response
browse %temp.html

Server-Response is also copied to %temp.html and Rebol will navigate to it with your default browser:

You can then parse and browse to the result page:
parse/all server-response [
thru {Location: }
copy google-result to newline
to end
]
browse to-url google-result
Click on the picture and you will be transported to the best Rebol Tutorial on the Internet by my famous Rebol’s Friend Nick Antonaccio (see also his 8h youtube video tutorials!).

Note: if you type
read http://google.com/search?q=rebol%20tutorial&btnI=I'm+Feeling+Lucky
It would return the html content of the target site like if you type the url in your browser you would directly go to the site.
See also Carl Sassenrath’s Tutorial.


















No comments yet.