Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;“400错误请求”;使用OpenSSL BIO进行请求时 我试图用OpenSSL连接我的C++网站,这就是我的: #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; } #包括“openssl/ssl.h” #包括“openssl/bio.h” #包括“openssl/err.h” #包括 int main() { 生物*生物; INTP; char*request=(char*)“GET/HTTPS/1.1\x0D\x0AHost:(网站)/auth.php\x0D\x0A\x43连接:Close\x0D\x0A\x0D\x0A”; charr[1024]; ERR_load_BIO_字符串(); SSL_加载_错误_字符串(); OpenSSL_添加_所有算法(); bio=bio_new_connect(“(网站):80”); 如果(bio==NULL) { printf(“BIO为null\n”);返回0; } 如果(生物)连接(生物)_C++_Ssl_Https_Openssl - Fatal编程技术网

&引用;“400错误请求”;使用OpenSSL BIO进行请求时 我试图用OpenSSL连接我的C++网站,这就是我的: #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; } #包括“openssl/ssl.h” #包括“openssl/bio.h” #包括“openssl/err.h” #包括 int main() { 生物*生物; INTP; char*request=(char*)“GET/HTTPS/1.1\x0D\x0AHost:(网站)/auth.php\x0D\x0A\x43连接:Close\x0D\x0A\x0D\x0A”; charr[1024]; ERR_load_BIO_字符串(); SSL_加载_错误_字符串(); OpenSSL_添加_所有算法(); bio=bio_new_connect(“(网站):80”); 如果(bio==NULL) { printf(“BIO为null\n”);返回0; } 如果(生物)连接(生物)

&引用;“400错误请求”;使用OpenSSL BIO进行请求时 我试图用OpenSSL连接我的C++网站,这就是我的: #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; } #包括“openssl/ssl.h” #包括“openssl/bio.h” #包括“openssl/err.h” #包括 int main() { 生物*生物; INTP; char*request=(char*)“GET/HTTPS/1.1\x0D\x0AHost:(网站)/auth.php\x0D\x0A\x43连接:Close\x0D\x0A\x0D\x0A”; charr[1024]; ERR_load_BIO_字符串(); SSL_加载_错误_字符串(); OpenSSL_添加_所有算法(); bio=bio_new_connect(“(网站):80”); 如果(bio==NULL) { printf(“BIO为null\n”);返回0; } 如果(生物)连接(生物),c++,ssl,https,openssl,C++,Ssl,Https,Openssl,char*request=(char*)“GET/HTTPS/1.1\x0D\x0AHost:(网站)/auth.php\x0D\x0A\x43连接:Close\x0D\x0A\x0D\x0A”; 改为: const char request[] = "GET /auth.php HTTP/1.1\r\n" "Host: www.example.com\r\n" "Connection: Close\r\n\r\n"; bio = BIO_new_connect( "www.e

char*request=(char*)“GET/HTTPS/1.1\x0D\x0AHost:(网站)/auth.php\x0D\x0A\x43连接:Close\x0D\x0A\x0D\x0A”;

改为:

const char request[] = "GET /auth.php HTTP/1.1\r\n"
    "Host: www.example.com\r\n"
    "Connection: Close\r\n\r\n";
bio = BIO_new_connect( "www.example.com:443" );
(感谢Sam Varshavchik和Lightness在轨道上比赛捕捉到了HTTPS/1.1)


bio=bio\u new\u connect((网站):80”);

改为:

const char request[] = "GET /auth.php HTTP/1.1\r\n"
    "Host: www.example.com\r\n"
    "Connection: Close\r\n\r\n";
bio = BIO_new_connect( "www.example.com:443" );

您可能也对OpenSSL wiki感兴趣。您似乎缺少了我希望看到的东西,例如
SSL\u CTX\u new
BIO\u set\u conn\u hostname
SSL\u set\u tlsextu host\u name
BIO\u do\u handshake
和其他一些东西

今后,请停止编辑重要信息,如
(网站)
。任何人都不能用丢失的信息重复您的问题

C++可以使OpenSSL更容易使用。可以避免使用“代码> EVPiCiffelCCTXFILUE/<代码>使用Visual> UNQuyGyPTR < /C> >对某些函数进行明确的调用。对于一些C++示例,请参阅OpenSSL维基等,

char*request=(char*)“GET/HTTPS/1.1\x0D\x0AHost:(网站)/auth.php\x0D\x0A\x43连接:Close\x0D\x0A\x0D\x0A”;

改为:

const char request[] = "GET /auth.php HTTP/1.1\r\n"
    "Host: www.example.com\r\n"
    "Connection: Close\r\n\r\n";
bio = BIO_new_connect( "www.example.com:443" );
(感谢Sam Varshavchik和Lightness在轨道上比赛捕捉到了HTTPS/1.1)


bio=bio\u new\u connect((网站):80”);

改为:

const char request[] = "GET /auth.php HTTP/1.1\r\n"
    "Host: www.example.com\r\n"
    "Connection: Close\r\n\r\n";
bio = BIO_new_connect( "www.example.com:443" );

您可能也对OpenSSL wiki感兴趣。您似乎缺少了我希望看到的东西,例如
SSL\u CTX\u new
BIO\u set\u conn\u hostname
SSL\u set\u tlsextu host\u name
BIO\u do\u handshake
和其他一些东西

今后,请停止编辑重要信息,如
(网站)
。任何人都不能用丢失的信息重复您的问题


C++可以使OpenSSL更容易使用。可以避免使用C++使用代码> > EppIIIcPieldCxxFiels请不要将文字设置<代码>请求> <代码> > <代码>(char *)< /C> >,使用<代码> const char *请求=“…”。您是从教程还是示例开始工作的?我似乎记得,在启动

SSL
部分之前,您必须打开一个正常的TCP套接字。
HTTP
GET
请求中的协议说明符始终是
HTTP/x.y
。假定连接已加密的事实并不会改变这一点ocol仍然是“HTTP/1.0”或“HTTP/1.1”,而不是“HTTPS/x.y”。这可能是也可能不是所显示代码的唯一问题。@SamVarshavchik:我打赌是的。是的,HTTPS是HTTP over SSL/TLS,所以头应该是HTTP(只是为了提供一些背景)。请不要将文本设置
请求
转换为
(char*)
,使用
const char*request=“…”
。您是从教程还是示例开始工作的?我似乎记得,在启动
SSL
部分之前,您必须打开一个正常的TCP套接字。
HTTP
GET
请求中的协议说明符始终是
HTTP/x.y
。假定连接已加密的事实并不会改变这一点ocol仍然是“HTTP/1.0”或“HTTP/1.1”,而不是“HTTPS/x.y”。这可能是也可能不是显示的代码的唯一问题。@SamVarshavchik:我打赌是这样。是的,HTTPS是HTTP over SSL/TLS,所以头应该是HTTP(只是为了提供一些背景)。为什么不
const char*
?@LightnessRacesinOrbit
const char*
浪费指针的内存。
const char[]
更好。@EJP:Huh?
const char[]
将整个文本复制到一个新数组中,这个数组比指针占用的内存要多得多。相反,在编写了
const char*
之后,我不希望2018年的任何sane编译器都无法优化指针存储。为什么不
const char*
?@LightnessRacesinOrbit
const char*
浪费指针的内存。
const char[]
更好。@EJP:Huh?
const char[]
将整个文本复制到一个新数组中,这个数组比指针占用的内存要多得多。相反,在编写了
const char*
之后,我不希望2018年任何一个健全的编译器无法优化指针存储。