delphi 使用API返回网页信息

来源:互联网 发布:淘宝未评价就删除订单 编辑:程序博客网 时间:2024/06/09 19:53
uses WinInet
  1.  function GetIp(Url: PChar): string;  //向网页提交GET信息函数
  2. var
  3.   ErrCode: string;
  4.   hInternets, hInternetFiles: HINTERNET;
  5.   dwOut: DWORD;
  6.   lpBuffer: array[0..4096of Char;
  7. begin
  8.   ErrCode := 'heihei';
  9.   Result := ErrCode;
  10.   hInternets := InternetOpen('Huai_Huai', INTERNET_OPEN_TYPE_PRECONFIG, nilnil0);
  11.   if hInternets = nil then   
  12.   begin
  13.     Result := ErrCode;
  14.     Exit;
  15.   end;
  16.   hInternetFiles := InternetOpenUrl(hInternets, url, nil0, INTERNET_FLAG_DONT_CACHE or INTERNET_FLAG_RELOAD or INTERNET_FLAG_TRANSFER_BINARY, 0);
  17.   if hInternetFiles = nil then   
  18.   begin
  19.     InternetCloseHandle(hInternets);    
  20.     Result := ErrCode;    
  21.     Exit;
  22.   end;
  23.   dwOut := 0;    
  24.   Fillchar(lpBuffer, sizeof(lpBuffer), 0);    
  25.    
  26.   if InternetReadFile(hInternetFiles, @lpBuffer, 4096, dwOut) then
  27.     Result := lpBuffer
  28.   else
  29.     Result := ErrCode;
  30.   InternetCloseHandle(hInternets);
  31. end;
原创粉丝点击