I'm trying to connect to my website with OpenSSL for C++ and this is what I have:
#include "openssl/ssl.h"
#include "openssl/bio.h"
#include "openssl/err.h"
#include <string>
int main( )
{
BIO * bio;
int p;
char * request = (char*)"GET / HTTPS/1.1\x0D\x0AHost: (website)/auth.php\x0D\x0A\x43onnection: Close\x0D\x0A\x0D\x0A";
char r[ 1024 ];
ERR_load_BIO_strings( );
SSL_load_error_strings( );
OpenSSL_add_all_algorithms( );
bio = BIO_new_connect( "(website):80" );
if ( bio == NULL )
{
printf( "BIO is null\n" ); return 0;
}
if ( BIO_do_connect( bio ) <= 0 )
{
ERR_print_errors_fp( stderr );
BIO_free_all( bio );
return 0;
}
BIO_write( bio, request, strlen( request ) );
while(true)
{
p = BIO_read( bio, r, 1023 );
if ( p <= 0 ) break;
r[ p ] = 0;
printf( "%s", r );
}
BIO_free_all( bio );
system( "pause" );
return 0;
}
When I run this, I get this error:
HTTP/1.0 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>
Press any key to continue . . .
The website has an ssl certificate and whenever I try to connect to the main site it says that it has been moved to the same domain but with an https:// instead of http:// in front.
Where I enter my website I have it with www in front and of course the tld after. As you can see I'm trying to read from a PHP script so if anyone knows how I can fix this I'd appreciate it.