Click here to Skip to main content
12,398,181 members (50,697 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C Visual-Studio
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

#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 8-Oct-12 2:20am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Looks like your forgot to add WinHttp.lib to your linker inputs.
  Permalink  
Comments
Tarun Batra 8-Oct-12 8:50am
   
Sir do u have any idea how to call the C# service through VC++?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

It is about time you started to make better use of MSDN documentation[^].
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Add int main(int argc, char **argv) in the starting
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100