AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Sockets HTTPs on GitHub (https://forums.alliedmods.net/showthread.php?t=251226)

GuskiS 11-08-2014 10:19

Sockets HTTPs on GitHub
 
Hello. I'm trying to make an version check via github, but can't seem to get connected to github:
https://raw.githubusercontent.com/Gu...sion_check.txt
PHP Code:

#include <amxmodx>
#include <sockets>

new g_pSocket;

#define SCRIPT_NAME "/GuskiS/Trouble-in-Terrorist-Town/master/version_check.txt"
#define REMOTE_HOST "raw.githubusercontent.com"

public plugin_init()
{
    
set_task(5.0"connect_web");
}

public 
connect_web()
{
    new 
error;
    
g_pSocket socket_open(REMOTE_HOST443SOCKET_TCPerror);
    if(
g_pSocket 0)
    {
        new 
string[140];
        
formatex(stringcharsmax(string), "GET %s HTTP/1.1^nHost: %s^n^n"SCRIPT_NAMEREMOTE_HOST);
        
socket_send(g_pSocketstringcharsmax(string));
        
read_web();
    }
    else
    {
        switch(
error)
        {
            case 
1server_print("Error creating socket");
            case 
2server_print("Error resolving remote hostname");
            case 
3server_print("Error connecting socket");
        }
    }
}

public 
read_web()
{
    new 
text[2048];
    
socket_recv(g_pSockettextcharsmax(text));
    
server_print("^n%s"text);
    
server_print("%s^n"text[254]);


Output:
Code:


HTTP/1.1 400 Bad Request
Date: Sat, 08 Nov 2014 15:10:45 GMT
Server: Apache
Content-Length: 362
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request<
title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
Instead use the HTTPS scheme to access this URL, please.<br />

Is it even possible?

klippy 11-08-2014 14:13

Re: Sockets HTTPs on GitHub
 
You should use "^r^n" for a new line, not just "^n". That's how HTTP works.

GuskiS 11-09-2014 05:27

Re: Sockets HTTPs on GitHub
 
Thanks, but it doesn't work :(
I tried this:
PHP Code:

formatex(stringcharsmax(string), "GET %s HTTP/1.1^r^nHost: %s^r^n^r^n"SCRIPT_NAMEREMOTE_HOST);
formatex(stringcharsmax(string), "GET %s HTTP/1.1^r^nHost: %s^r^n"SCRIPT_NAMEREMOTE_HOST);
formatex(stringcharsmax(string), "GET %s HTTP/1.1^nHost: %s^r^n^r^n"SCRIPT_NAMEREMOTE_HOST);
formatex(stringcharsmax(string), "GET %s HTTP/1.1^nHost: %s^r^n"SCRIPT_NAMEREMOTE_HOST); 

None of them work, response is the same.

HamletEagle 11-09-2014 06:28

Re: Sockets HTTPs on GitHub
 
Idk much about http, but shouldn't you use HTTPS instead of HTTP ? Again, no ideea, just asking.

GuskiS 11-09-2014 06:40

Re: Sockets HTTPs on GitHub
 
As far as I have searched, there isn't such thing.

klippy 11-09-2014 09:22

Re: Sockets HTTPs on GitHub
 
Quote:

Originally Posted by HamletEagle (Post 2222027)
Idk much about http, but shouldn't you use HTTPS instead of HTTP ? Again, no ideea, just asking.

He is already using HTTPS, by connecting to remote on port 443.

@Guskis, try using port 80 or 8080 instead for HTTP.

YamiKaitou 11-09-2014 09:31

Re: Sockets HTTPs on GitHub
 
Quote:

Originally Posted by KliPPy (Post 2222076)
He is already using HTTPS, by connecting to remote on port 443.

Actually he is not, there is more to it than simply connecting on 443.

cURL output when using HTTPS
Code:

# curl -v https://google.com
* About to connect() to google.com port 443 (#0)
*  Trying 173.194.46.73... connected
* Connected to google.com (173.194.46.73) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*  CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_RSA_WITH_RC4_128_SHA
* Server certificate:
*      subject: CN=*.google.com,O=Google Inc,L=Mountain View,ST=California,C=US
*      start date: Oct 22 12:55:10 2014 GMT
*      expire date: Jan 20 00:00:00 2015 GMT
*      common name: *.google.com
*      issuer: CN=Google Internet Authority G2,O=Google Inc,C=US
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: google.com
> Accept: */*

cURL output when using Port 443
Code:

# curl -v google.com:443
* About to connect() to google.com port 443 (#0)
*  Trying 173.194.46.68... connected
* Connected to google.com (173.194.46.68) port 443 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: google.com:443
> Accept: */*

Notice how the HTTPS one sends SSL info and the 443 one does not.

GuskiS 11-09-2014 09:38

Re: Sockets HTTPs on GitHub
 
So, how should look that plugin?

klippy 11-09-2014 09:43

Re: Sockets HTTPs on GitHub
 
Just use HTTP? I hope github does not deny you because of it. :D

GuskiS 11-09-2014 10:24

Re: Sockets HTTPs on GitHub
 
Can you give me a working example? I can't get it to work :/


All times are GMT -4. The time now is 17:35.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.