使用wininet连接到Internet

时间:2014-02-24 03:07:48

标签: c wininet getlasterror

我使用Python的SimpleHTTPServer在127.0.0.1:8000在我的笔记本电脑上设置了一个临时服务器。我写了一个小C程序试图连接到服务器 并查看那里的文件d.txt。但是,我的程序没有正确连接。 HttpSendRequestA抛出ERROR_SXS_KEY_NOT_FOUND (00002EE7),但问题更严重。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <wininet.h>

int main(void) {

  HINTERNET* openHandle;
  openHandle = InternetOpenA("Windows+NT+5.1",0, NULL, NULL, 0);

  HINTERNET* connectHandle;
  connectHandle = InternetConnectA(openHandle,"127.0.0.1",8000,NULL,NULL,0,3,0);

  HINTERNET* httpHandle;
  char* arr[] = {"text//*", NULL};
  httpHandle = HttpOpenRequestA(connectHandle, "GET", "d.txt", "HTTP/1.1", 0,
               arr,0,0);

  int result2;
  result2 = HttpSendRequestA(httpHandle, 0,0,0,0);
  printf("%d",result2);

  return EXIT_SUCCESS;
}

0 个答案:

没有答案