Click here to Skip to main content
15,886,038 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have the following code to send the HTTP POST request but i get the errors as:-
a.obj : error LNK2019: unresolved external symbol __imp__WinHttpCloseHandle@4 referenced in function "int __cdecl _tmain(int,char * * const)" (?_tmain@@YAHHQAPAD@Z)
1>a.obj : error LNK2019: unresolved external symbol __imp__WinHttpReadData@16 referenced in function "int __cdecl _tmain(int,char * * const)" (?_tmain@@YAHHQAPAD@Z)
1>a.obj : error LNK2019: unresolved external symbol __imp__WinHttpQueryDataAvailable@8 referenced in function "int __cdecl _tmain(int,char * * const)" (?_tmain@@YAHHQAPAD@Z)
1>a.obj : error LNK2019: unresolved external symbol __imp__WinHttpReceiveResponse@8 referenced in function "int __cdecl _tmain(int,char * * const)" (?_tmain@@YAHHQAPAD@Z)
1>a.obj : error LNK2019: unresolved external symbol __imp__WinHttpSendRequest@28 referenced in function "int __cdecl _tmain(int,char * * const)" (?_tmain@@YAHHQAPAD@Z)
1>a.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpenRequest@28 referenced in function "int __cdecl _tmain(int,char * * const)" (?_tmain@@YAHHQAPAD@Z)
1>a.obj : error LNK2019: unresolved external symbol __imp__WinHttpConnect@16 referenced in function "int __cdecl _tmain(int,char * * const)" (?_tmain@@YAHHQAPAD@Z)
1>a.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpen@20 referenced in function "int __cdecl _tmain(int,char * * const)" (?_tmain@@YAHHQAPAD@Z)
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup


C++
#include <windows.h>
#include <Winhttp.h>

#include <stdlib.h>
#include<stdio.h>
#include<conio.h>
//int main()
	int _tmain(int argc, char* argv[])
{
  DWORD dwSize = 0;
  DWORD dwDownloaded = 0;
  LPSTR pszOutBuffer;
  BOOL  bResults = FALSE;
  HINTERNET  hSession = NULL, 
             hConnect = NULL,
             hRequest = NULL;

  // Use WinHttpOpen to obtain a session handle.
  hSession = WinHttpOpen( L"WinHTTP Example/1.0",  
                          WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
                          WINHTTP_NO_PROXY_NAME, 
                          WINHTTP_NO_PROXY_BYPASS, 0 );

  // Specify an HTTP server.
 /* if( hSession )
    hConnect = WinHttpConnect( hSession, L"http://192.168.15.167/NHMS_Service/NHMS_Service.svc",
                               INTERNET_DEFAULT_HTTPS_PORT, 0 );*/
    // Specify an HTTP server.
  if( hSession )
    hConnect = WinHttpConnect( hSession, L"http://localhost/HelloWorld/Service.asmx",
                               INTERNET_DEFAULT_HTTPS_PORT, 0 );

  // Create an HTTP request handle.
  if( hConnect )
    hRequest = WinHttpOpenRequest( hConnect, L"POST", NULL,
                                   NULL, WINHTTP_NO_REFERER, 
                                   WINHTTP_DEFAULT_ACCEPT_TYPES, 
                                   WINHTTP_FLAG_SECURE );

  // Send a request.
  if( hRequest )
    bResults = WinHttpSendRequest( hRequest,
                                   WINHTTP_NO_ADDITIONAL_HEADERS, 0,
                                   WINHTTP_NO_REQUEST_DATA, 0, 
                                   0, 0 );


  // End the request.
  if( bResults )
    bResults = WinHttpReceiveResponse( hRequest, NULL );

  // Keep checking for data until there is nothing left.
  if( bResults )
  {
    do 
    {
      // Check for available data.
      dwSize = 0;
      if( !WinHttpQueryDataAvailable( hRequest, &dwSize ) )
        printf( "Error %u in WinHttpQueryDataAvailable.\n",
                GetLastError( ) );

      // Allocate space for the buffer.
      pszOutBuffer = new char[dwSize+1];
      if( !pszOutBuffer )
      {
        printf( "Out of memory\n" );
        dwSize=0;
      }
      else
      {
        // Read the data.
        ZeroMemory( pszOutBuffer, dwSize+1 );

        if( !WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, 
                              dwSize, &dwDownloaded ) )
          printf( "Error %u in WinHttpReadData.\n", GetLastError( ) );
        else
          printf( "%s", pszOutBuffer );

        // Free the memory allocated to the buffer.
        delete [] pszOutBuffer;
      }
    } while( dwSize > 0 );
  }


  // Report any errors.
  if( !bResults )
    printf( "Error %d has occurred.\n", GetLastError( ) );

  // Close any open handles.
  if( hRequest ) WinHttpCloseHandle( hRequest );
  if( hConnect ) WinHttpCloseHandle( hConnect );
  if( hSession ) WinHttpCloseHandle( hSession );
  return 0;
}


What should i do to remove them?
Posted

Looks like your forgot to add WinHttp.lib to your linker inputs.
 
Share this answer
 
Comments
Tarun Batra 8-Oct-12 8:50am    
Sir do u have any idea how to call the C# service through VC++?
It is about time you started to make better use of MSDN documentation[^].
 
Share this answer
 
Comments
Tarun Batra 8-Oct-12 9:15am    
Sir do u have any idea how to call the C# service through VC++?
Richard MacCutchan 8-Oct-12 9:45am    
Why don't you follow the link I posted and please read the documentation? You will then learn:
1. What include and lib files you need to add to your project
2. What other methods a particular class provides.
3. In many cases code samples that you can use to solve your problem.
4. And most importantly, how to find things out for yourself.
Add int main(int argc, char **argv) in the starting
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900