在c++中使用wininet时发生链接器错误


Linker error using wininet in c++

我将使用c++中的wininet上传数据
这是一个代码。

        #include "stdafx.h"
    #include "iostream"
    #include "windows.h"
    #include "wininet.h"
    #include "tchar.h"
    #include "iostream"
    #include "string"
    #include "sstream"
    #pragma comment(lib, "ws2_32.lib")
    int main(){
            TCHAR hdrs[] = _T("Content-Type: application/x-www-form-urlencoded");
    TCHAR frmdata[] = _T("name=John+Doe&userid=hithere&other=P%26Q");
    LPCTSTR accept[] = {_T("*/*"), NULL};
    HINTERNET hSession = InternetOpen(_T("MyAgent"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    HINTERNET hConnect = InternetConnect(hSession, _T("http://localhost"), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
    HINTERNET hRequest = HttpOpenRequest(hConnect, _T("POST"), _T("/upload.php"), NULL, NULL, accept, 0, 1);
    HttpSendRequest(hRequest, hdrs, _tcslen(hdrs), frmdata, _tcslen(frmdata));

       return 0;
        }

我正在使用visual studio 2012进行编译。
我也在dev c++中编译了它,但错误是一样的。

1>asdfg.obj:错误LNK2019:未解析的外部符号__imp__InternetOpenW@20在函数_main 中引用

1>asdfg.obj:错误LNK2019:未解析的外部符号__imp__InternetConnectW@32在函数_main中引用
1>asdfg.obj:错误LNK2019:未解析的外部符号__imp__HttpOpenRequestW@32在函数_main中引用
1>asdfg.obj:错误LNK2019:未解析的外部符号__imp__HttpSendRequestW@20在函数_main 中引用

更新
我也在使用#pragma comment(lib, "Wininet.lib"),没有出现任何错误
所有程序都编译成功,但数据没有上传
这是php文件。

<?php
    $name = $_POST['name'];
    $userid = $_POST['userid'];
    $other = $_POST['other'];
    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
    $txt1 = $name."'n";
    fwrite($myfile, $txt1);
    $txt2 = $userid."'n";
    fwrite($myfile, $txt2);
    $txt3 = $other."'n";
    fwrite($myfile, $txt3);
    fclose($myfile);
   ?>

您需要链接到正确的库,对于<wininet.h>,它是Wininet.lib

此外,当您包含像wininet.hsstream.h这样的系统头时,您应该将它们的名称包含在< >中,而不是用于本地项目文件的" "中。