HttpSendRequestEx function
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: HttpSendRequestEx function

  1. #1
    Join Date
    Aug 1999
    Location
    CA, USA
    Posts
    47

    HttpSendRequestEx function

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



    }


  2. #2
    Join Date
    Oct 2000
    Location
    Funchal, Madeira, Portugal
    Posts
    10

    Re: HttpSendRequestEx function

    I have a similar problem, but I'm using PUT. Also would like an answer to this.

    Those who give up never win,
    and those who win never give up

    Luis Abreu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center