在 MFC 中使用 GetHttpConnection

Using GetHttpConnection in MFC

本文关键字:GetHttpConnection MFC      更新时间:2023-10-16

我有一个用java编写的休息服务器,我正在尝试从MFC客户端调用GET方法。

服务器 URL http://localhost:8080/com.test.simpleServlet/api/customers,当我运行 crome 邮递员插件时,这会向我返回正确的值。我已经实现了Java Restful WebService作为服务器,com.test.simpleServlet作为servlet。

现在,我正在尝试实现客户端以使用 MFC 调用此 URL。这是我的示例代码。

CString strServerName = L"http://localhost:8080/com.test.simpleServlet";
           INTERNET_PORT nPort = 8080;

pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, L"/api/customers"); //strObject);
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);

我无法完成这项工作,并且收到错误12007(无法解析服务器名称)

pFile->SendRequest();

我想我在这里做了一些非常愚蠢的事情,但不幸的是我无法弄清楚。我不确定服务器URL是否正确传递。我把它当作"http://localhost:8080/com.test.simpleServlet"传递。

请您指导。

谢谢苏尼尔

这是一个非常愚蠢的错误。代码应该是

CString strServerName = L"http://localhost";
.............
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, L"/com.test.simpleServlet/api/customers");
相关文章:
  • 没有找到相关文章