Hi,
i am trying using below code for connect to server but there are some errors.
Can anybody help me?
#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;
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");
hSession = WinHttpOpen( L"A WinHTTP Example Program/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);
httpResult = WinHttpQueryOption( hSession, WINHTTP_OPTION_CONNECT_TIMEOUT,
&data, &dwSize);
if (httpResult)
printf("Connect time-out:\t%u ms\n",data);
hConnect = WinHttpConnect( hSession, L"msdn.microsoft.com",
INTERNET_DEFAULT_HTTP_PORT, 0);
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);
httpResult = WinHttpQueryOption( hRequest, WINHTTP_OPTION_URL,
NULL, &dwSize);
pwszURL = new WCHAR[dwSize/sizeof(WCHAR)];
httpResult = WinHttpQueryOption( hRequest, WINHTTP_OPTION_URL,
(void *)pwszURL, &dwSize);
printf("Redirected URL:\t\t%S\n",pwszURL);
delete [] pwszURL;
httpResult = WinHttpCloseHandle(hRequest);
if (!httpResult)
printf("Could not close the hRequest handle.\n");
httpResult = WinHttpCloseHandle(hConnect);
if (!httpResult)
printf("Could not close the hConnect handle.\n");
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,