问题描述
我使用实现 HTTPS POST 请求的 Poco 库创建了以下 C++ 程序。
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Streamcopier.h>
#include <Poco/URI.h>
#include <Poco/File.h>
#include <iostream>
#include <string>
#include <stdio.h>
using Poco::Net::HTTPSClientSession;
using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;
using Poco::Net::HTTPMessage;
using Poco::URI;
using Poco::File;
using namespace std;
using namespace Poco;
using namespace Poco::Net;
int main()
{
try
{
URI uri = URI("https://example.com/login");
string path(uri.getPathAndQuery());
if (path.empty())
path = "/";
Context::Ptr ctx = new Context(Context::TLSV1_2_CLIENT_USE,"",Context::VERIFY_NONE,9,true,"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
HTTPSClientSession session(uri.getHost(),uri.getPort(),ctx);
HTTPRequest request(HTTPRequest::HTTP_POST,path,HTTPMessage::HTTP_1_1);
std::string body("this is a random request body\r\n0\r\n");
request.setContentLength((int) body.length());
session.sendRequest(request) << body;
HTTPResponse response;
istream &is = session.receiveResponse(response);
string responseStr;
Streamcopier::copyToString(is,responseStr);
cout << "response is " << responseStr << endl;
}
catch (Poco::Exception& exc)
{
cout << "Poco Exception occured during https request." << endl;
cout << "message: " << exc.message() << endl;
}
}
当我为我的 Ubuntu 20.04 amd64 arch 构建它时它工作正常并且响应是正确的
response is <?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="//wpc.75674.betacdn.net/0075674/www/ec_tpm_bcon.js"></script>
</body>
</html>
之后,我为 arm64 arch 构建了它,并尝试在基于我按照 Dockerfile 构建的映像的 docker 容器中运行它:
FROM arm64v8/ubuntu:20.04
workdir /opt/myapp
ENV DEBIAN_FRONTEND=noninteractive
copY myapp .
RUN apt-get clean
RUN apt-get update
RUN apt-get install libssl-dev nano iputils-ping curl -y
# cleanup
RUN apt-get -qy autoremove
RUN echo "/opt/myapp/libs" >> /etc/ld.so.conf && \
ldconfig
EXPOSE 2
EXPOSE 8022
EXPOSE 443
EXPOSE 80
CMD ["bash"]
之后我使用以下命令运行容器
docker run -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static -i -t --platform arm64 myapp_image
程序运行到第 session.sendRequest(request) << body;
行
终端给出以下错误:
getsockopt level=1 optname=20 not yet supported
捕获的异常是:
Net Exception: Operation not supported
另一方面,当我在容器内给出命令时:
curl -d '{json}' -H 'Content-Type: application/json' https://example.com/login
我得到与 amd64 arch case 相同的打印输出:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="//wpc.75674.betacdn.net/0075674/www/ec_tpm_bcon.js"></script>
</body>
</html>
gcc/g++ 和 aarch64-linux-gnu-g++/aarch64-linux-gnu-gcc 编译器,我使用多架构功能构建相同版本的 9.3.0。
有人知道我可能做错了什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)