WinHttpFormSubmitSample

WinHttpFormSubmitSample

本文介绍了问题编译/链接WinHTTP示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试使用以下代码连接到服务器,但存在一些错误.
有人可以帮我吗?

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;
}



我的错误如下:

1> ------构建开始:项目:111,配置:Debug Win32 ------
1>正在编译...
1> 111.cpp
1>正在链接...
1> 111.obj:错误LNK2019:函数_wmain中引用的未解析的外部符号__imp__WinHttpCrackUrl @ 16
1> 111.obj:错误LNK2019:在函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"中引用的未解析的外部符号__imp__WinHttpCloseHandle @ 4(?WinHttpFormSubmitSample @@ YAHPB_WGPA_ />1> 111.obj:错误LNK2019:函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"(?WinHttpFormSubmitSample @@ YAHPB_WGPA_)引用的未解析的外部符号__imp__WinHttpQueryHeaders @ 24 />1> 111.obj:错误LNK2019:在函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"中引用的未解析的外部符号__imp__WinHttpReceiveResponse @ 8(?WinHttpFormSubmitSample @ _YAHPB_WG />1> 111.obj:错误LNK2019:在函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"中引用的未解析的外部符号__imp__WinHttpWriteData @ 16(?WinHttpFormSubmitSample @@ YAHPB_WGPA_ />1> 111.obj:错误LNK2019:函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"中引用的未解析的外部符号__imp__WinHttpSendRequest @ 28(?WinHttpFormSubmitSample @@ YAHPB_WGPA_ />1> 111.obj:错误LNK2019:在函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"中引用的未解析的外部符号__imp__WinHttpAddRequestHeaders @ 16(?WinHttpFormSubmitSample @@ YHPB_WG />1> 111.obj:错误LNK2019:在函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"中引用的未解析的外部符号__imp__WinHttpOpenRequest @ 28(?WinHttpFormSubmitSample @@ YAHPB_WGPA_W />1> 111.obj:错误LNK2019:在函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"中引用了未解决的外部符号__imp__WinHttpConnect @ 16(?WinHttpFormSubmitSample @@ YAHPB_WGPA 1> 111.obj:错误LNK2019:在函数"int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)"中引用的未解析的外部符号__imp__WinHttpOpen @ 20(?WinHttpFormSubmitSample @@ YAHPB_WGPA 1> C:\ Users \ Reza \ Desktop \ 111 \ Debug \ 111.exe:致命错误LNK1120:10个未解决的外部组件
1>构建日志保存在文件://c:\ Users \ Reza \ Desktop \ 111 \ 111 \ Debug \ BuildLog.htm"中
1> 111-11个错误,0个警告
========== Build:0成功,1失败,0最新,跳过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,

推荐答案



这篇关于问题编译/链接WinHTTP示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 17:43