C++ 从主机向在VirtualBox linux计算机上运行的服务器发送http请求
我目前正在使用微软的cpprestsdk开发一个名为Casablanca的REST服务器 我使用Oracle的VirtualBox在linux虚拟机上运行服务器 我已经将VM设置为使用桥接适配器网络,并且可以成功地将SSH连接到机器中,这样我就知道可以向我的服务器发送http请求 我的服务器的终结点当前设置为:C++ 从主机向在VirtualBox linux计算机上运行的服务器发送http请求,c++,http,virtual-machine,virtualbox,casablanca,C++,Http,Virtual Machine,Virtualbox,Casablanca,我目前正在使用微软的cpprestsdk开发一个名为Casablanca的REST服务器 我使用Oracle的VirtualBox在linux虚拟机上运行服务器 我已经将VM设置为使用桥接适配器网络,并且可以成功地将SSH连接到机器中,这样我就知道可以向我的服务器发送http请求 我的服务器的终结点当前设置为: http://localhost:4200/api" 请参见下面my main.cpp中的代码: int main() { cout << "Starting Se
http://localhost:4200/api"
请参见下面my main.cpp中的代码:
int main() {
cout << "Starting Server" << endl;
TransactionController server;
server.setEndpoint("http://localhost:4200/api");
server.initHandlers();
try {
server.openServer().wait();
cout << "Server listening at: " << server.getEndpoint() << endl;
// figure out how to keep server running without this?
while (true);
}
catch(exception &e) {
cout << "--- ERROR DETECTED ---" << endl;
cout << e.what() << endl;
}
// this doesn't get reached bc of the while(true)
server.closeServer().wait();
return 0;
}
现在我的问题是,如何使用HTTP客户端(如Postman或Advanced Rest客户端)从主机执行相同的请求
我不确定在试图从主机查询在来宾计算机上运行的服务器时,会将什么作为请求URL
使用ifconfig,我知道来宾计算机的ip地址是:
10.0.0.157
我可以使用这个地址SSH到我的VM中,所以我知道这是我的客户机的正确地址
但是,我不知道如何将http请求发送到运行我的服务器的这台计算机
我不是网络方面的专家,也不是卡萨布兰卡方面的专家,所以任何正确方向的指导或指点都将不胜感激。谢谢你抽出时间 您已将服务器绑定到localhost,因此它只能从localhost获得。 我不知道
TransactionController::setEndpoint
做什么,但您可能需要执行以下操作之一:
server.setEndpoint("http://10.0.0.157:4200/api"); // bind to only 10.0.0.157
server.setEndpoint("http://0.0.0.0:4200/api"); // bind to all ipv4 adresses
server.setEndpoint("http://*:4200/api"); // bind to all addresses
以上哪项工作将取决于setEndpoint
的实现
server.setEndpoint("http://10.0.0.157:4200/api"); // bind to only 10.0.0.157
server.setEndpoint("http://0.0.0.0:4200/api"); // bind to all ipv4 adresses
server.setEndpoint("http://*:4200/api"); // bind to all addresses