Login Register






C++ Web Browser filter_list
Author
Message
C++ Web Browser #1
Can someone please tell me how to make a web browser in C++ using jGRASP? I finally got into computer programming in school, and this is the program they want me to use. I have already made a small program in class, though the teacher did not explain any of the code, she just said to type it and run it. This is not needed for my class, but I would like to know how to do it. I was thinking of possibly adding a media player into it.

Thanks,
Vallex Koten

Reply

RE: C++ Web Browser #2
http://stackoverflow.com/questions/74729...eb-browser
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: C++ Web Browser #3
it's actually easy to make a web browser thats basic...

You just need to know the HTTP\0.9 spec

You would socket connect on port 80 to your site and send the following

Code:
HTTP\0.9 GET /\r\n \r\n \r\n

and read the response. It will include the header (delimited by \r\n\r\n) and then the entire index page

Reply

RE: C++ Web Browser #4
(12-18-2014, 06:02 AM)phyrrus9 Wrote: it's actually easy to make a web browser thats basic...

You just need to know the HTTP\0.9 spec

You would socket connect on port 80 to your site and send the following

Code:
HTTP\0.9 GET /\r\n \r\n \r\n

and read the response. It will include the header (delimited by \r\n\r\n) and then the entire index page

Why 0.9 and not the standard 1.1 or even 1.0?

And you have left out the part of actually parsing the webpage, loading other resources, etc. The part you mentioned is simple, but thats only a very small part of the web browser functionality.

Reply

RE: C++ Web Browser #5
(12-18-2014, 06:02 AM)phyrrus9 Wrote: it's actually easy to make a web browser thats basic...

You just need to know the HTTP\0.9 spec

You would socket connect on port 80 to your site and send the following

Code:
HTTP\0.9 GET /\r\n \r\n \r\n

and read the response. It will include the header (delimited by \r\n\r\n) and then the entire index page

What the fuck is that? Thats not how a HTTP GET packet looks like.

Code:
GET /newreply.php HTTP/1.1\r\n Host: sinister.ly\r\n User-Agent: Penis

This is more like it.

Reply

RE: C++ Web Browser #6
(12-18-2014, 11:11 AM)dopamine Wrote: What the fuck is that? Thats not how a HTTP GET packet looks like.

Code:
GET /newreply.php HTTP/1.1\r\n Host: sinister.ly\r\n User-Agent: Penis

This is more like it.

Actually since he is suggesting the use of the 0.9 protocol that more or less is what an HTTP request looks like. Though you don't need the "HTTP/0.9" before the request - it can be omitted - I am unsure if putting it there is part of the actual specification or if it will be ignored or what - but everything else is correct.

HTTP/0.9 doesn't support headers, so things like host and user-agent wouldn't work. This is probably due to the fact that widespread use of virtual hosts didn't come until later - so you wouldn't have needed to specify the host, it was assumed that the page responding at that ip/address is the one you wanted. Unlike nowadays when 1 server may have 100 clients on the same IP.

But I do question his recommendation to use the simple implementation of HTTP over the current standard of HTTP/1.1

So he wasn't way off base for his example, could be 100% correct i'm not entirely sure. worst case he should have omitted the HTTP/0.9 text but I just know it works without it - I am unsure if the specification says to put it there or not though.

Reply

RE: C++ Web Browser #7
(12-18-2014, 11:11 AM)dopamine Wrote: What the fuck is that? Thats not how a HTTP GET packet looks like.

Code:
GET /newreply.php HTTP/0.9\r\n Host: sinister.ly\r\n User-Agent: Penis

This is more like it.

The fields you specified are optional fields.

Here is a basic web browser written in C++ (utilizes the libsocket framework)

Given, a web browser does not have to have ANY HTML parsing. This one does not, but it is still a web browser in essence.

Code:
#include "libsocket.h" #include <stdio.h> #include <string.h> #include <time.h> int main(int argc, char * * argv) { clientSocket *conn = new clientSocket("74.125.196.101", 80); char c, buf[1024]; printf("%02x\n", conn->getStatus()); sprintf(buf, "GET / HTTP/1.0\r\n\r\n"); //sample packet header conn->Write(buf, strlen(buf)); sleep(3); //give a tad delay while (conn->Read(&c, 1) > 0) printf("%c", c); fflush(stdout); conn->Close(); return 0; }

Reply

RE: C++ Web Browser #8
(12-18-2014, 12:54 PM)phyrrus9 Wrote: The fields you specified are optional fields.

The fields he specified are optional in HTTP specifications 1.0 and 1.1. They are not supported in HTTP 0.9.

So your edit to change the HTTP/1.1 to HTTP/0.9 in his example code is pointless. anything after the GET isnt supported.

Why are you so insistent on using 0.9 though?? it's very limited in its implementation.

Reply

RE: C++ Web Browser #9
The request was for a browser. I simply used the version that came into my head first. I could have used 1.0, but I wanted to stick basic.

The example program was just to demonstrate that the terminology used by OP was flawed in that there were not enough specifics to correctly help. I did, in fact, write a web browser in my code. Not a whole lot of use, but it was done.

Reply