Hi

I am using WinIntet API in appication for connecting to Http Servers.

My application needs to connect to Jav Servlet running on Web Logic, POST some data and get the data returned by Servlet

Here is the Code I have written.. All the API's I am using are going successfully... But on the other servlet I don't see any data I am sending...

I would appreciate if any one tell me what is going wrong with this code.. Am I missing anything here

Thanks
Kishore

#include <iostream>
#include <string>

#include <windows.h>
#include <wininet.h>

using namespace std;

string strServerName("63.100.96.126");
int iPort=7001;
string strServelet("AmStoreString");

void main(void)
{

HINTERNET m_hInternetSession,m_hInternetConnect;

m_hInternetSession=InternetOpen("TESTPROJ",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,INTERNET_FLAG_DONT_CACHE);

if (m_hInternetSession == NULL)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL);
LocalFree(lpMsgBuf);
return;
}

m_hInternetConnect=InternetConnect(m_hInternetSession,strServerName.c_str(),iPort,"","",INTERNET_SERVICE_HTTP,0,0);

if (m_hInternetConnect == NULL)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL);
LocalFree(lpMsgBuf);
return;
}

HINTERNET hOpenRequest=NULL;

//Opening the HTTP request to the "strServelet" servlet on the Server
hOpenRequest=HttpOpenRequest(m_hInternetConnect,"POST",strServelet.c_str(),NULL,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE,0);
if(hOpenRequest == NULL)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL);
LocalFree(lpMsgBuf);

return;
}

char strTett[100];
memset(strTett,0,100);
memcpy(strTett,"ClearerID=TestID&Password=Test",31);

// Filling the InternetBuffers which will be sent to Servlet
INTERNET_BUFFERS BufferIn;

BufferIn.dwStructSize=sizeof(INTERNET_BUFFERS);
BufferIn.Next=NULL;
BufferIn.lpcszHeader=NULL;
BufferIn.dwHeadersLength=0;
BufferIn.dwHeadersTotal=0;
BufferIn.lpvBuffer=NULL;
BufferIn.dwBufferLength=0;
BufferIn.dwBufferTotal=strlen(strTett);
BufferIn.dwOffsetLow=0;
BufferIn.dwOffsetHigh=0;

//Sending the request to the server through the Http POST
if(!HttpSendRequestEx(hOpenRequest,&BufferIn,NULL,HSR_INITIATE,0))
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL);
LocalFree(lpMsgBuf);
InternetCloseHandle(hOpenRequest);

return;
}

DWORD dwNoBytesRead=0;
DWORD dwBytesWritten=0;

if(!InternetWriteFile(hOpenRequest,strTett,strlen(strTett),&dwBytesWritten))
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL);
LocalFree(lpMsgBuf);
InternetCloseHandle(hOpenRequest);
return;
}

// Ending the Send Request
if(!HttpEndRequest(hOpenRequest,NULL,HSR_INITIATE,0))
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL);
LocalFree(lpMsgBuf);

InternetCloseHandle(hOpenRequest);
return;
}

char strTempBuffer[1024];
memset(strTempBuffer,0,1024);

if (!InternetReadFile(hOpenRequest,strTempBuffer,1024,&dwNoBytesRead))
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL);
LocalFree(lpMsgBuf);

InternetCloseHandle(hOpenRequest);
return;
}

cout<<strTempBuffer<<endl;

// Closing the Handles
InternetCloseHandle(hOpenRequest);
InternetCloseHandle(m_hInternetConnect);
InternetCloseHandle(m_hInternetSession);



}