Created
April 16, 2011 19:25
-
-
Save carlosdelfino/923406 to your computer and use it in GitHub Desktop.
A idéia é receber um fluxo continuo de texto de um servidor WEB e imprimir sempre que preciso.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program httpstream; | |
uses | |
Forms, | |
Ustream in 'Ustream.pas' {Fstream}; | |
{$R *.res} | |
begin | |
Application.Initialize; | |
Application.CreateForm(TFstream, Fstream); | |
Application.Run; | |
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Fstream: TFstream | |
Left = 332 | |
Top = 118 | |
Width = 332 | |
Height = 500 | |
Caption = 'HTTP Stream ' | |
Color = clBtnFace | |
Font.Charset = DEFAULT_CHARSET | |
Font.Color = clWindowText | |
Font.Height = -11 | |
Font.Name = 'MS Sans Serif' | |
Font.Style = [] | |
OldCreateOrder = False | |
PixelsPerInch = 96 | |
TextHeight = 13 | |
object GroupBox1: TGroupBox | |
Left = 0 | |
Top = 40 | |
Width = 321 | |
Height = 425 | |
Caption = 'Imprimindo' | |
TabOrder = 0 | |
object Memo1: TMemo | |
Left = 2 | |
Top = 15 | |
Width = 317 | |
Height = 408 | |
Align = alClient | |
Lines.Strings = ( | |
'Memo1') | |
TabOrder = 0 | |
end | |
end | |
object Button1: TButton | |
Left = 8 | |
Top = 8 | |
Width = 75 | |
Height = 25 | |
Caption = 'Button1' | |
TabOrder = 1 | |
OnClick = Button1Click | |
end | |
object Edit1: TEdit | |
Left = 120 | |
Top = 8 | |
Width = 65 | |
Height = 21 | |
ReadOnly = True | |
TabOrder = 2 | |
Text = 'Edit1' | |
end | |
object IdHTTP2: TIdHTTP | |
MaxLineAction = maException | |
ReadTimeout = 0 | |
AuthRetries = 0 | |
AllowCookies = True | |
ProxyParams.BasicAuthentication = False | |
ProxyParams.ProxyPort = 0 | |
Request.ContentLength = -1 | |
Request.ContentRangeEnd = 0 | |
Request.ContentRangeStart = 0 | |
Request.ContentType = 'text/html' | |
Request.Accept = 'text/html, */*' | |
Request.BasicAuthentication = False | |
Request.Host = 'localhost' | |
Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library) (CSAT)' | |
HTTPOptions = [hoForceEncodeParams] | |
Left = 88 | |
Top = 8 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit Ustream; | |
interface | |
uses | |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | |
Dialogs, StdCtrls, IdIOHandler, IdIOHandlerStream, IdBaseComponent, | |
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP; | |
type | |
TFstream = class(TForm) | |
IdHTTP2: TIdHTTP; | |
GroupBox1: TGroupBox; | |
Memo1: TMemo; | |
Button1: TButton; | |
Edit1: TEdit; | |
procedure Button1Click(Sender: TObject); | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
Fstream: TFstream; | |
implementation | |
uses DateUtils; | |
{$R *.dfm} | |
procedure TFstream.Button1Click(Sender: TObject); | |
var | |
input: TStringStream; | |
output: TMemoryStream; | |
postStr: string; | |
postRespStr:string; | |
begin | |
input :=TStringStream.Create(''); | |
output :=TMemoryStream.Create; | |
// no local do número informado para id, substituir com o codigo do posto | |
// mesmo passando o login e senha é bom conferir o codigo do posto também | |
postStr:='Login=painel&password=0b82&id=1'; | |
With IdHTTP2 do | |
begin | |
Request.UserAgent :='CSAT Browser - v0.1 (Nothing Compatible)'; | |
Request.Accept :='text/html'; | |
Request.AcceptLanguage :='pt-BR;q=0.7,en;q=0.3'; | |
Request.AcceptEncoding :='gzip,deflate'; | |
Request.AcceptCharset :='utf-8;q=0.7,*;q=0.7'; | |
Request.BasicAuthentication := False; | |
Request.Connection :='keep-alive'; | |
// IdHTTP2.Request.referer:='http://???????????'; | |
Request.ContentType :='application/x-www-form-urlencoded'; | |
Request.ContentLength :=length(postStr); | |
// Headers are only example too... | |
//Request.CustomHeaders.Add('POST /cps2_admin/senhas HTTP/1.1'); | |
Request.CustomHeaders.Add('Keep-Alive: 300'); | |
Request.Host:= 'localhost'; | |
end; | |
input.writestring(postStr); | |
IdHTTP2.post('http://localhost/cps2_admin/senhas',input,output); | |
{ | |
apartir deste ponto após o post se confirmar como 200, entro num loop infinito | |
pegando o conteudo do output e trando ele e enviando para a impressora sempre que preciso. | |
} | |
Edit1.Text := IntToStr(IdHTTP2.ResponseCode); | |
{} | |
output.WriteComponent(Memo1); | |
{} | |
Memo1.Lines.Add(IdHTTP2.Response.ResponseText); | |
input.free; | |
output.free; | |
// MemoryStream.Free; | |
end; | |
end. | |
{ | |
Dicas de impressão: | |
http://www.tecnobyte.com.br/dica3.html | |
Verificar se está conectado: | |
http://www.tecnobyte.com.br/dica5.html#dica84 | |
Outras Dicas: | |
http://www.efg2.com/Lab/Library/Delphi/IO/StreamIO.htm | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Veja um exemplo em perl no link: https://gist.github.com/923532