Using GetHttpConnection in MFC

2.2k views Asked by At

I have a rest Server written in java and I am trying to call a GET method from an MFC client.

The server URL is http://localhost:8080/com.test.simpleServlet/api/customers and this returns me the proper value when I run through the crome postman plugin. I have implemented Java Restful WebService as the Server, with com.test.simpleServlet as a servlet.

Now I am trying to implement a Client to call this URL using MFC. This is my sample code.

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);

I am not able to make this work and I get the error 12007(The server name could not be resolved) at

pFile->SendRequest();

I guess I am doing something very silly here, but unfortunately I am not able to figure it out. I am not sure if the ServerURL is passed correctly. I had passed it as "http://localhost:8080/com.test.simpleServlet".

Request you to kindly guide.

Thanks Sunil

1

There are 1 answers

0
S_R On BEST ANSWER

It was a very silly mistake. The code should be

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