douaoli5328 2015-03-28 13:23
浏览 97

在c ++中使用wininet的链接器错误[重复]

I'm going to upload data using wininet in c++.
Here is a code.

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

        }

I am using visual studio 2012 for compiling it.
I also compile it in dev c++ but the error is same.

1>asdfg.obj : error LNK2019: unresolved external symbol __imp__InternetOpenW@20 referenced in function _main

1>asdfg.obj : error LNK2019: unresolved external symbol __imp__InternetConnectW@32 referenced in function _main
1>asdfg.obj : error LNK2019: unresolved external symbol __imp__HttpOpenRequestW@32 referenced in function _main
1>asdfg.obj : error LNK2019: unresolved external symbol __imp__HttpSendRequestW@20 referenced in function _main

UPDATE
I'm using #pragma comment(lib, "Wininet.lib") also and getting no error.
all the program compile successfully but the data is not upload.
here is php file.

<?php

    $name = $_POST['name'];
    $userid = $_POST['userid'];
    $other = $_POST['other'];

    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
    $txt1 = $name."
";
    fwrite($myfile, $txt1);
    $txt2 = $userid."
";
    fwrite($myfile, $txt2);
    $txt3 = $other."
";
    fwrite($myfile, $txt3);
    fclose($myfile);

   ?>
</div>
  • 写回答

1条回答 默认 最新

  • duan1979768678 2015-03-28 13:27
    关注

    You need to link against the correct library, for <wininet.h> it is Wininet.lib.

    Also, when you include system headers like wininet.h or sstream.h, you should enclose their names in < > rather than " ", which are for local project files.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line