VC ++中的Http Post

时间:2013-08-05 18:39:01

标签: visual-c++ wininet

我在这里附加了我的代码我不知道为什么我收到错误12005,尽管URL是正确的。我无法透露我的网址。请帮我解决一下这个。尝试添加一些其他URL并检查它是否正常工作。

#include "stdafx.h"
#include "conio.h"
#include "Windows.h"
#include "WinInet.h"
int main()
{
    HINTERNET connect = InternetOpen(L"MyBrowser",0 ,0, 0, 0);
    if (!connect)
    {
       printf("Connection Failed or Syntax error");
       return 0;
    }

HINTERNET OpenAddress = InternetConnect(connect, L"https://mydomain.com", INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP,0,0);
    if (!OpenAddress)
    {
        DWORD ErrorNum = GetLastError();
        printf("Failed to open URL" );//<< endl << " Error No: "  ErrorNum;
        InternetCloseHandle(connect);
        return 0;
    }
    else
    {
        printf("Opened Successfully");
    }

    HINTERNET hHttpRequest = HttpOpenRequest(OpenAddress, L"POST", L"name=name&age=age&height=height", 0, 0, 0, INTERNET_FLAG_RELOAD, 0);

    if(!HttpSendRequest(hHttpRequest, NULL,0, NULL, 0)) 
    {
        DWORD dwErr = GetLastError();
        printf("\nError");
        printf("%d",dwErr); 
    }

    InternetCloseHandle(connect);
    InternetCloseHandle(OpenAddress);
    InternetCloseHandle(hHttpRequest);
    return 0;
}

0 个答案:

没有答案