在MFC中使用GetHttpConnection

时间:2015-06-14 09:44:01

标签: c++ mfc jersey wininet winhttp

我有一个用java编写的rest服务器,我试图从MFC客户端调用GET方法。

服务器网址为http://localhost:8080/com.test.simpleServlet/api/customers,当我浏览crome postman插件时,这会返回正确的值。 我已经将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();

我想我在做一些非常愚蠢的事情,但不幸的是我无法弄明白。我不确定ServerURL是否正确传递。 我已将其作为" http://localhost:8080/com.test.simpleServlet"。

传递

请您指导。

由于 苏尼

1 个答案:

答案 0 :(得分:0)

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

CString strServerName = L"http://localhost";
.............
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, L"/com.test.simpleServlet/api/customers");