Click here to Skip to main content

Tarun Batra asked:

Open original thread
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?
Tags: C++, C, Visual-Studio

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
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