Closed xanderdunn closed 3 years ago
I just noticed in the curl header that the response is HTTP/2. Perhaps this parsing error is just a manifestation of oatpp/oatpp#116?
curl --http1.1
on the same endpoint works, so I don't think HTTP/2 is the issue. The server also supports HTTP/1.1.
Hello @xanderdunn ,
Here is the code that works for me:
#include <iostream>
#include "oatpp/web/client/ApiClient.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include OATPP_CODEGEN_BEGIN(ApiClient) ///< Begin code-gen section
class MyApiClient : public oatpp::web::client::ApiClient {
API_CLIENT_INIT(MyApiClient)
API_CALL("GET", "/api/markets", getMarkets)
};
#include OATPP_CODEGEN_END(ApiClient) ///< End code-gen section
#include "oatpp/web/client/HttpRequestExecutor.hpp"
#include "oatpp/core/base/StrBuffer.hpp"
#include "oatpp/core/Types.hpp"
#include "oatpp-openssl/client/ConnectionProvider.hpp"
#include "oatpp-openssl/Config.hpp"
#include <csignal>
using namespace oatpp::network;
using namespace oatpp::web;
using namespace oatpp::parser;
int main() {
std::signal(SIGPIPE, SIG_IGN);
/* create connection provider */
//auto config = oatpp::openssl::Config::createShared(); // also works
auto config = oatpp::openssl::Config::createDefaultClientConfigShared();
auto connectionProvider =
oatpp::openssl::client::ConnectionProvider::createShared(config,{"ftx.com", 443});
auto requestExecutor = client::HttpRequestExecutor::createShared(connectionProvider);
auto client = MyApiClient::createShared(requestExecutor, NULL);
auto response = client->getMarkets();
std::cout << response->getStatusCode() << std::endl;
std::cout << response->readBodyToString()->std_str() << std::endl;
return EXIT_SUCCESS;
}
cmake:
find_package(OpenSSL 1.1 REQUIRED)
find_package(oatpp 1.2.5 REQUIRED)
find_package(oatpp-openssl 1.2.5 REQUIRED)
target_link_libraries(my-example
# oatpp
PUBLIC oatpp::oatpp
PUBLIC oatpp::oatpp-openssl
# third-party
PUBLIC OpenSSL::SSL
PUBLIC OpenSSL::Crypto
)
Please make sure to use the latest oatpp
and oatpp-openssl
. Notice that the latest oatpp-openssl
has no "oatpp-openssl/Callbacks.hpp"
file.
Regards, Leonid
Thanks @lganzzzo, in the coming days I will try this with 1.2.5 as soon as I can. I was on 1.2.0, the latest version in vcpkg. I opened microsoft/vcpkg#17504 to make it easily available to my project.
I just upgraded to 1.2.5 and updated my code and this is working as expected now, thank you!
This produces the output I expect to see:
Now comment out the curl-backed
requestExecutor
and uncommentauto requestExecutor = client::HttpRequestExecutor::createShared(connectionProvider);
, running it again produces this error:It appears to be this failure to read the headers.