C ++ WinHttpSendRequest错误C2664

时间:2019-06-11 07:29:48

标签: c++ windows login

我正在尝试制作一个程序,该程序从需要您通过另一个站点登录的网站获取HTML。 我遇到WinHttpSendRequest的问题。 我希望所有这些都不会出错。

  1. 代码:

    len = (DWORD)strlen("username=aan1982&pswd=admin1234&sub_check=1&sub_login=");
    bResult = WinHttpSendRequest(hRequest,
        WINHTTP_NO_ADDITIONAL_HEADERS,
        0,
        "username=aan1982&pswd=admin1234&sub_check=1&sub_login=",
        len,
        len,
        0);
    

    错误:

    C2664 'BOOL' WinHttpSendRequest(HINTERNET,LPCWSTR,DWORD,LPVOID,DWORD,DWORD,DWORD_PTR)': cannot convert argument 4 from 'const char [55]' to 'LPVOID'
    
  2. 代码:

    LPVOID data = "username=aan1982&pswd=admin1234&sub_check=1&sub_login=";
    len =     (DWORD)strlen("username=aan1982&pswd=admin1234&sub_check=1&sub_login=");
    bResult = WinHttpSendRequest(hRequest,
        WINHTTP_NO_ADDITIONAL_HEADERS,
        0,
        data,
        len,
        len,
        0);
    

    错误:

    C2440    'initializing': cannot convert from 'const char [55]' to 'LPVOID'  
    
  3. 代码:

    len = (DWORD)strlen("username=aan1982&pswd=admin1234&sub_check=1&sub_login=");
    bResult = WinHttpSendRequest(hRequest,
        WINHTTP_NO_ADDITIONAL_HEADERS,
        0,
        (LPVOID)"username=aan1982&pswd=admin1234&sub_check=1&sub_login=",
        len,
        len,
        0);
    

    错误:

    LNK1120 9 unresolved externals
    LNK2019 unresolved external symbol __imp__WinHttpCloseHandle@4 referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl GetHTML(void)" (?GetHTML@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)  
    

    和其他8个类似LNK2019的

1 个答案:

答案 0 :(得分:0)

char    p[] = "username=aan1982&pswd=admin1234&sub_check=1&sub_login=";
LPVOID  ptr = static_cast<LPVOID>( p );
int     len = strlen( p );