在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.h
或sstream.h
这样的系统头时,您应该将它们的名称包含在< >
中,而不是用于本地项目文件的" "
中。
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- Visual Studio mkl_link_tool.exe链接错误
- C++ 实现模板单例类时出现链接错误
- 使用类模板的方法链接错误
- MySQL C++连接器链接错误
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- 运行 C++ 单元测试时LNK2005链接错误
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 链接错误,包括我创建的相同头文件 - C++
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 使用标头保护的多个定义链接错误
- 链接错误:未定义对 stdscr 和 wgetch 的引用
- 使用 Vivek 的 Vcam / 捕获源过滤器构建/链接错误
- 升压program_options中的链接错误
- 使用 g++ 预处理器进行替换会导致链接错误
- 在调试配置中编译工作正常,但发布会给出链接错误
- 相邻矩阵设置链接错误
- 包含常量变量并包含在多个文件中的标头的链接错误
- C++链接错误,我理解但无法解决
- 是什么导致macOS Mojave上的GoogleTest链接错误