AsuMagic
|
|
Posted on: February 14, 2014, 04:32:36 pm |
|
|
Joined: Nov 2013
Posts: 23
|
Hey, I just don't understand how to download a HTML page ( In my case api.kag2d.com ). I turned on the network stuff in ENIGMA API. Someone told me I'd need to do net_init(), apisock = net_connect_tcp("api.kag2d.com",80,true), msg = "GET / HTTP/1.1"; tcp_send_raw(apisock,msg,string_length(msg)); and the stuff to receive the data. The problem is that apisock is equal to -4. ENIGMA wiki says negative values returns an error but it does not give a list of the errors. I don't have any idea how to do it. Can someone explain me how do it works and an example to get the page api.kag2d.com? Just telling I'm a pure noob at networking stuff and not a pro at ENIGMA, I'm much more habitued to GM.
|
|
|
Logged
|
|
|
|
|
|
|
|
Goombert
|
|
Reply #5 Posted on: February 15, 2014, 07:09:45 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
I see why, it's not the function it's how our website is set up. I just put the following into the create event of an Object. show_message(net_http("google.com","")); It worked and produced the following.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
|
TheExDeus
|
|
Reply #7 Posted on: February 16, 2014, 10:17:40 am |
|
|
Joined: Apr 2008
Posts: 1860
|
The function is the one Robert linked too. The code is:
string net_http(string host, string loc) { char *packet;
int s = net_connect_tcp(host,"http",0); if (s < 0) die("Connect",0);
char *cmd = "\ GET %s HTTP/1.1\r\n\ Host: %s\r\n\ User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0\r\n\ Connection: close\r\n\r\n"; int len = prepare(&packet,cmd,2,loc.c_str(),host.c_str()); int r = net_send_raw(s,packet,len); free(packet); if (r < 0) die("Send",1,s);
do { if ((packet = (char*)net_receive(s).c_str()) == NULL) die("Receive",1,s);
//HTTP 1.1 requires handling of 100 Continue. while (strstr(packet,"HTTP/1.1 100 Continue\r\n") != NULL) packet = strstr(packet,"\r\n\r\n") + 4; //skip the header packet = strstr(packet,"\r\n\r\n"); } while (packet == NULL); //packet not filled? Go back for more. packet += 4;
closesocket(s); return packet; }
|
|
|
Logged
|
|
|
|
Goombert
|
|
Reply #8 Posted on: February 16, 2014, 12:37:58 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Is there a way to know what's doing / what did a function? Rephrase that because I don't know what you mean.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
|
Goombert
|
|
Reply #10 Posted on: February 16, 2014, 02:46:03 pm |
|
|
Location: Cappuccino, CA Joined: Jan 2013
Posts: 2993
|
Ah, it's like in Firefox when you right click and view the source code of a web page. It retrieves the code of the webpage.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.
|
|
|
|
TheExDeus
|
|
Reply #12 Posted on: February 17, 2014, 08:12:50 am |
|
|
Joined: Apr 2008
Posts: 1860
|
I'd bet it's because of bad encryption ( ANSI instead of UTF or reverse for example ) so the request is bugged out. I think it because of encryption (https) in general (not coding like your ANSI/UTF thinking). The site https://api.kag2d.com/ is encrypted with TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, 256 bit keys. That means the request also needs to be encrypted and the response decrypted. The function does nothing like that. Here is the request sent by the function: GET HTTP/1.1\r\n\ Host: https://api.kag2d.com/\r\n\ User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0\r\n\ Connection: close\r\n\r\n There are many things you could try to send it, but encryption is not supported by that function (it would require handshaking, certificates and a lot of other things to work). So try disabling encryption. Later either we or yourself maybe can figure out how to make it work with encryption.
|
|
|
Logged
|
|
|
|
|
|
|