Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Beginner Networking
Hi,
i am trying using below code for connect to server but there are some errors.
Can anybody help me?
/************************************************************
*                                                           *
* RetOptions.cpp                                            *
*                                                           *
* Copyright (c) Microsoft Corporation. All Rights Reserved. *
*                                                           *
************************************************************/
 
#include #windows.h#
#include #winhttp.h#;
#include #stdio.h#

 
int main(int argc, char* argv[])
{
    HINTERNET hSession;
    HINTERNET hConnect;
    HINTERNET hRequest;
    BOOL httpResult;
    DWORD data;
    DWORD dwSize = sizeof(DWORD);
    LPWSTR pwszURL;
 

    // Print a description of the sample.
    printf("This sample demonstrates the process for retrieving WinHTTP\n");
    printf("options programmatically from a C/C++ application. WinHTTP\n");
    printf("application programming interface (API) functions are used to\n");
    printf("determine the default connect time-out value and to find the\n");
    printf("current URL after an HTTP request is redirected.\n\n");
 
    // Use WinHttpOpen to obtain a session handle.
    hSession = WinHttpOpen(  L"A WinHTTP Example Program/1.0", 
                             WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
                             WINHTTP_NO_PROXY_NAME, 
                             WINHTTP_NO_PROXY_BYPASS, 0);
 
    // Use WinHttpQueryOption to retrieve Internet options.
    httpResult = WinHttpQueryOption( hSession, WINHTTP_OPTION_CONNECT_TIMEOUT, 
                                     &data, &dwSize);
    if (httpResult) 
        printf("Connect time-out:\t%u ms\n",data);
 
    // Use WinHttpConnect to specify an HTTP server.
    hConnect = WinHttpConnect( hSession, L"msdn.microsoft.com",
                               INTERNET_DEFAULT_HTTP_PORT, 0);
 
    // Open and Send a Request Header.
    hRequest = WinHttpOpenRequest( hConnect, L"GET", 
                         L"/downloads/samples/internet/winhttp/retoptions/redirect.asp", 
                         NULL, WINHTTP_NO_REFERER, 
                         WINHTTP_DEFAULT_ACCEPT_TYPES, 0);                     
    httpResult = WinHttpSendRequest( hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 
                                     0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
    httpResult = WinHttpReceiveResponse( hRequest, NULL);
 
    // Use WinHttpQueryOption again, this time to obtain a buffer size.
    httpResult = WinHttpQueryOption( hRequest, WINHTTP_OPTION_URL, 
                                     NULL, &dwSize);
    pwszURL = new WCHAR[dwSize/sizeof(WCHAR)];
    
    // Use WinHttpQueryOption to retrieve Internet options.
    httpResult = WinHttpQueryOption( hRequest, WINHTTP_OPTION_URL, 
                                     (void *)pwszURL, &dwSize);
    printf("Redirected URL:\t\t%S\n",pwszURL);
 
    // Free the allocated memory.
    delete [] pwszURL;
 
    // When finished, release the hRequest handle.
    httpResult = WinHttpCloseHandle(hRequest);
    if (!httpResult)
        printf("Could not close the hRequest handle.\n");
 
    // When finished, release the hConnect handle.
    httpResult = WinHttpCloseHandle(hConnect);
    if (!httpResult)
        printf("Could not close the hConnect handle.\n");
 
    // When finished, release the hSession handle.
    httpResult = WinHttpCloseHandle(hSession);
    if (!httpResult)
        printf("Could not close the hSession handle.\n");
 

    return 0;
}
 
my error is as below:

1>------ Build started: Project: 111, Configuration: Debug Win32 ------
1>Compiling...
1>111.cpp
1>Linking...
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpCrackUrl@16 referenced in function _wmain
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpCloseHandle@4 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpQueryHeaders@24 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpReceiveResponse@8 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpWriteData@16 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpSendRequest@28 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpAddRequestHeaders@16 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpenRequest@28 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpConnect@16 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpen@20 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>C:\Users\Reza\Desktop\111\Debug\111.exe : fatal error LNK1120: 10 unresolved externals
1>Build log was saved at "file://c:\Users\Reza\Desktop\111\111\Debug\BuildLog.htm"
1>111 - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

Best Regards,
Posted 6-May-10 9:35am
Rezame951
Edited 6-May-10 10:42am
Moak11.4K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think perhaps you forgot to add Winhttp.lib to your linker options.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

dear sir,
thank you for your reply.
yes, you are right. I added that and works now.
I am beginner in C++.
Now I connect to my website and want know how I must add my parameter in above code for sending request to server and after that hoe get response from server for using that in my program.
Thanks.
  Permalink  
Comments
Richard MacCutchan at 7-May-10 6:33am
   
I'm afraid I have not used these services so cannot help, but you should be able to find what you need in MSDN. Try this link http://msdn.microsoft.com/en-us/library/aa384273(VS.85).aspx

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

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 6 May 2010
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