使用WiNET在C++中连接错误 我将用WiNET在C++中上传数据。 这是一个代码 #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; }

使用WiNET在C++中连接错误 我将用WiNET在C++中上传数据。 这是一个代码 #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; },php,c++,visual-studio-2012,linker,Php,C++,Visual Studio 2012,Linker,我正在使用visual studio 2012进行编译。 我也在DEV C++中编译,但是错误是一样的。 1> asdfg.obj:错误LNK2019:未解析的外部符号\uuu imp__InternetOpenW@20在函数_main中引用 1> asdfg.obj:错误LNK2019:未解析的外部符号\uuu imp__InternetConnectW@32在函数_main中引用 1> asdfg.obj:错误LNK2019:未解析的外部符号\uuu imp__HttpOpenRequest

我正在使用visual studio 2012进行编译。 我也在DEV C++中编译,但是错误是一样的。 1> asdfg.obj:错误LNK2019:未解析的外部符号\uuu imp__InternetOpenW@20在函数_main中引用

1> asdfg.obj:错误LNK2019:未解析的外部符号\uuu imp__InternetConnectW@32在函数_main中引用 1> asdfg.obj:错误LNK2019:未解析的外部符号\uuu imp__HttpOpenRequestW@32在函数_main中引用 1> asdfg.obj:错误LNK2019:未解析的外部符号\uuu imp__HttpSendRequestW@20在函数_main中引用

更新 我正在使用pragma commentlib和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.lib


此外,当您包含wininet.h或sstream.h等系统标题时,您应该将它们的名称括在<>中,而不是用于本地项目文件。

您需要链接wininet.lib。您需要链接其他库wininet.lib。@Axeem您的编辑构成了一个全新的问题,请再问一个问题。