Raised This Month: $ Target: $400
 0% 

Sockets HTTPs on GitHub


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 11-08-2014 , 10:19   Sockets HTTPs on GitHub
Reply With Quote #1

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?
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness

Last edited by GuskiS; 11-08-2014 at 10:22.
GuskiS is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-08-2014 , 14:13   Re: Sockets HTTPs on GitHub
Reply With Quote #2

You should use "^r^n" for a new line, not just "^n". That's how HTTP works.
klippy is online now
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 11-09-2014 , 05:27   Re: Sockets HTTPs on GitHub
Reply With Quote #3

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.
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-09-2014 , 06:28   Re: Sockets HTTPs on GitHub
Reply With Quote #4

Idk much about http, but shouldn't you use HTTPS instead of HTTP ? Again, no ideea, just asking.
__________________
HamletEagle is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-09-2014 , 09:22   Re: Sockets HTTPs on GitHub
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
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.
klippy is online now
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 11-09-2014 , 09:31   Re: Sockets HTTPs on GitHub
Reply With Quote #6

Quote:
Originally Posted by KliPPy View Post
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.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 11-09-2014 at 09:32.
YamiKaitou is offline
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 11-09-2014 , 06:40   Re: Sockets HTTPs on GitHub
Reply With Quote #7

As far as I have searched, there isn't such thing.
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS is offline
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 11-09-2014 , 09:38   Re: Sockets HTTPs on GitHub
Reply With Quote #8

So, how should look that plugin?
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness

Last edited by GuskiS; 11-09-2014 at 09:40.
GuskiS is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-09-2014 , 09:43   Re: Sockets HTTPs on GitHub
Reply With Quote #9

Just use HTTP? I hope github does not deny you because of it.
klippy is online now
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 11-09-2014 , 10:24   Re: Sockets HTTPs on GitHub
Reply With Quote #10

Can you give me a working example? I can't get it to work :/
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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