"400 Bad request"使用 OpenSSL BIO 进行请求时
"400 Bad request" when using OpenSSL BIO for request
我正在尝试使用C 的OpenSSL连接到我的网站,这就是我所拥有的:
#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.1x0Dx0AHost: (website)/auth.phpx0Dx0Ax43onnection: Closex0Dx0Ax0Dx0A";
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 nulln" ); 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;
}
当我运行此问题时,我会收到此错误:
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 . . .
该网站具有SSL证书,每当我尝试连接到主站点时,它都说它已移至同一域,但使用https://而不是http://在前面。
当我进入我的网站的位置,我将其与www一起在前面,当然还有TLD之后。如您所见,我正在尝试从PHP脚本阅读,因此,如果有人知道我如何解决这个问题,我会欣赏它。
char * request = (char*)"GET / HTTPS/1.1x0Dx0AHost: (website)/auth.phpx0Dx0Ax43onnection: Closex0Dx0Ax0Dx0A";
更改为:
const char request[] = "GET /auth.php HTTP/1.1rn"
"Host: www.example.comrn"
"Connection: Closernrn";
(感谢Sam Varshavchik和轨道上的轻度比赛,以捕获 HTTPS/1.1
(。
bio = BIO_new_connect( "(website):80" );
更改为:
bio = BIO_new_connect( "www.example.com:443" );
您可能还对OpenSSL Wiki上的SSL/TLS客户端感兴趣。您似乎缺少我希望看到的东西,例如SSL_CTX_new
,BIO_set_conn_hostname
,SSL_set_tlsext_host_name
,BIO_do_handshake
等。
将来,请停止编辑重要信息,例如(website)
。没有人可以通过缺少信息来复制您的问题。
c 可以使使用OpenSSL更容易。您可以使用unique_ptr
避免使用EVP_CIPHER_CTX_free
等功能的明确调用。有关某些C 示例,请参见EVP对称加密和解密|openssl Wiki,unique_ptr和openssl的stack_of(x509( *,如何将pkcs7_sign结果纳入char *或std :: string等,
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 如何在boost beast http请求中设置http头
- 发送一个带有libcurl C++问题的帖子请求:s
- 在多个核心中处理一个HTTP请求
- OpenSSL BIO and SSL_read
- 错误:请求非类类型为"MULTIMEDIA_FILME [500]"的成员|
- 使用 Winsock2.h C++向不和谐 API 发送 HTTP 请求时出现问题
- 每个服务器请求的内存预算
- std::getline没有在while循环中重新请求用户输入
- 请求最简单的 OpenMP 目标 GPU 示例
- 请求有关C++中嵌入 for 循环的帮助
- 错误:请求从"常量字符 [5]"转换为非标量类型"字符串"
- 使用 winsock 接收 http 请求
- QNetworkAccessManager 稍后在添加请求时删除
- 为什么我收到来自谷歌的错误请求?
- 从网链套接字请求连接设备的列表
- libcurl :C++处理多个异步请求
- 对于 http 请求,python 比 c++ 快吗?
- 通过引用传递向量是请求 std::分配器
- "400 Bad request"使用 OpenSSL BIO 进行请求时