Witam
Jestem początkujący jeżeli chodzi o Delphi, postanowiłem napisać prostą aplikację za pomocą której będę mógł resetować modem Thomson TCM 420 którego używa się w większości kablówek. bez potrzeby uzywania www. Aplikacja działa na komponencie winsock dołączanym dynamicznie mam jednak z nia 2 problemy.
-
Zresetowanie modemu następuje dopiero gdy 2 razy kliknę w button, dlaczego nie działa gdy klikne raz?
-
Dlaczego w niektórych miejscach mogę normalnie wstawić " . " (kropka) a w innych muszę jako hex bo inaczej aplikacja nic nie wysyła? przykład: New.Socket.SendText('POST /goform/set_scan_page HTTP/1' + hex('00') + ('1') + hex('0A')); jeżeli mam "HTTP/1.1 to aplikacja niczego nie wysyła a więc kropkę musiałem zapisac jako hex. Oto cały kod.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, ComCtrls, ExtCtrls, OleCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure NewRead(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
New : TClientSocket;
Dane : String;
implementation
{$R *.dfm}
Function Hex(strData:string): string;
var sresult:string; sfinal:string; hexc:cardinal; i:integer;
begin
i:=1;
while i<=length(strData) do
begin
hexc := strtoint('$' + copy(strData,i,2));
sresult := inttostr(hexc);
sresult := chr(strtoint(sresult));
sfinal := sfinal + sresult;
i:=i+2;
end;
result := sfinal
end;
procedure TForm1.NewRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo1.lines.add(Dane);
Memo1.SelLength := length(Memo1.Text);
Memo1.SelStart := length(Memo1.Text);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
New := TClientSocket.Create(self);
New.Address := ('192.168.100.1');
New.Port := 80;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
New.Active :=True;
IF New.Active = True then
New.Socket.SendText('POST /goform/set_scan_page HTTP/1' + hex('00') + ('1') + hex('0A'));
New.Socket.SendText('Host: 192.168.100.1' + hex('0A'));
New.Socket.SendText('User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1' + hex('0A'));
New.Socket.SendText('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' + hex('0A'));
New.Socket.SendText('Accept-Language: pl,en-us;q=0.7,en;q=0.3' + hex('0A'));
New.Socket.SendText('Accept-Encoding: gzip, deflate' + hex('0A'));
New.Socket.SendText('Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7' + hex('0A'));
New.Socket.SendText('Connection: keep-alive' + hex('0A'));
New.Socket.SendText('Referer: http://192.168.100.1/set_scan_page.asp' + hex('0A'));
New.Socket.SendText('Content-Type: application/x-www-form-urlencoded' + hex('0A'));
New.Socket.SendText('Content-Length: 20' + hex('0A') + hex('0A'));
New.Socket.SendText('CmInfoDsFreq1=&CmInfoUsId1=' + hex('0A'));
Button1.Click;
end;
end.