Guest User

Jeff DeVore

a guest
Sep 11th, 2009
5,451
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function sslInet(Const AServer, AUrl, AData : AnsiString; blnSSL:Boolean = True): AnsiString;
  2. var
  3. aBuffer     : Array[0..4096] of Char;
  4. Header      : TStringStream;
  5. BufStream   : TMemoryStream;
  6. sMethod     : AnsiString;
  7. BytesRead   : Cardinal;
  8. pSession    : HINTERNET;
  9. pConnection : HINTERNET;
  10. pRequest    : HINTERNET;
  11. begin
  12.  
  13.  Result := '';
  14.  
  15.  pSession := InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  16.  
  17.  if Assigned(pSession) then
  18.    try
  19.  
  20.      case blnSSL of
  21.        True  :  pConnection := InternetConnect(pSession, PChar(AServer), INTERNET_DEFAULT_HTTPS_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
  22.        False :  pConnection := InternetConnect(pSession, PChar(AServer), INTERNET_DEFAULT_HTTP_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
  23.      end;
  24.  
  25.   if Assigned(pConnection) then
  26.     try
  27.  
  28.       if (AData = '') then
  29.         sMethod := 'GET'
  30.       else
  31.         sMethod := 'POST';
  32.  
  33.      case blnSSL of
  34.        True  : pRequest := HTTPOpenRequest(pConnection, PChar(sMethod), PChar(AURL), nil, nil, nil, INTERNET_FLAG_SECURE  or INTERNET_FLAG_KEEP_CONNECTION, 0);
  35.        False : pRequest := HTTPOpenRequest(pConnection, PChar(sMethod), PChar(AURL), nil, nil, nil, INTERNET_SERVICE_HTTP, 0);
  36.      end;
  37.  
  38.   if Assigned(pRequest) then
  39.     try
  40.  
  41.       Header := TStringStream.Create('');
  42.       with Header do
  43.         begin
  44.           WriteString('Host: ' + AServer + sLineBreak);
  45.           WriteString('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10'+SLineBreak);
  46.           WriteString('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'+SLineBreak);
  47.           WriteString('Accept-Language: en-us,en;q=0.5' + SLineBreak);
  48.           WriteString('Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'+SLineBreak);
  49.           WriteString('Keep-Alive: 300'+ SLineBreak);
  50.           WriteString('Connection: keep-alive'+ SlineBreak+SLineBreak);
  51.         end;
  52.  
  53.       HttpAddRequestHeaders(pRequest, PChar(Header.DataString), Length(Header.DataString), HTTP_ADDREQ_FLAG_ADD);
  54.  
  55.  
  56.   if HTTPSendRequest(pRequest, nil, 0, Pointer(AData), Length(AData)) then
  57.     begin
  58.  
  59.      BufStream := TMemoryStream.Create;
  60.      try
  61.  
  62.        while InternetReadFile(pRequest, @aBuffer, SizeOf(aBuffer), BytesRead) do
  63.          begin
  64.            if (BytesRead = 0) then Break;
  65.            BufStream.Write(aBuffer, BytesRead);
  66.          end;
  67.  
  68.          aBuffer[0] := #0;
  69.          BufStream.Write(aBuffer, 1);
  70.          Result := PChar(BufStream.Memory);
  71.  
  72.      finally
  73.        FreeAndNil(BufStream);
  74.      end;
  75.     end;
  76.  
  77.     finally
  78.       InternetCloseHandle(pRequest);
  79.       FreeAndNil(Header);
  80.     end;
  81.  
  82.     finally
  83.       InternetCloseHandle(pConnection);
  84.     end;
  85.  
  86.     finally
  87.       InternetCloseHandle(pSession);
  88.     end;
  89. end;
  90.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×