网站首页 > 物联资讯 > 技术分享

http协议使用实例

2016-09-28 00:00:00 广州睿丰德信息科技有限公司 阅读
睿丰德科技 专注RFID识别技术和条码识别技术与管理软件的集成项目。质量追溯系统、MES系统、金蝶与条码系统对接、用友与条码系统对接

#include <stdio.h>
#include <windows.h>
#include <wininet.h>

#define MAXSIZE 1024
#pragma comment(lib, "Wininet.lib")

void urlopen(TCHAR*);

int main(int argc, TCHAR* argv[])
{
 TCHAR ch[] = TEXT("http://dt.163.com/images/news/0605/news02053101_5.jpg");
 urlopen(ch);
 getchar();
 return 0;
}

void urlopen(TCHAR* url)
{
 HINTERNET hSession = InternetOpen(TEXT("UrlTest"), INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, NULL, NULL, 0);
 if(hSession != NULL)
 {
  HINTERNET hHttp = InternetOpenUrl(hSession, url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
  BYTE Temp[MAXSIZE];
  ULONG Number = 1;
  DWORD written;
  HANDLE hFile;

  if (hHttp != NULL)
  {
   wprintf_s(TEXT("%s\n"), url);

   
   hFile = CreateFile( TEXT("ysl.jpg"),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
   if ( hFile == INVALID_HANDLE_VALUE )
   {
    goto hear;
   }
   while (Number > 0)
   {
    InternetReadFile(hHttp, Temp, MAXSIZE - 1, &Number);
    Temp[Number] = '\0';
    WriteFile( hFile,Temp,Number, &written,NULL);
   }
   InternetCloseHandle(hHttp);
   hHttp = NULL;
  }
hear:
  CloseHandle( hFile );
  InternetCloseHandle(hSession);
  hSession = NULL;
 } 
}

RFID管理系统集成商 RFID中间件 条码系统中间层 物联网软件集成