Autor Beitrag
delphist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

WIN XP, 98, 95; SUSE LINUX 8.1, 6.1, 6.0

BeitragVerfasst: Fr 01.04.05 17:28 
Guten Abend,
Ich möchte Euch mein Socket-Problem in Delphi schildern und hoffe ein paar Ratschläge von Euch zu bekommen.
Ich schicke per SendText an einen HTTP-Server eine Datei.
Das klappt perfekt, wenn die Datei klein ist.
Bei größeren Dateien gibt's Probleme: Ich bekomme keine Antwort vom Server, obwohl die Daten komplett beim Server ankommen und verarbeitet werden.
Arbeite mit dem Ereignis Client1Read.
Hat jemand eine Idee, wie ich das Problem lösen könnte?
(Wie kann ich eine Fortschrittsanzeige realisieren? Geht so wohl nicht. Brauch ich da Buffer?)
Danke Euch!
delphist

_________________
3w + freehostlist + de
3w + bild-stoerung + de
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Fr 01.04.05 17:32 
Ohne Quelltext werden wir dir hier mit großer Wahrscheinlichkeit nicht weiterhelfen können ;)

AXMD
delphist Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64

WIN XP, 98, 95; SUSE LINUX 8.1, 6.1, 6.0

BeitragVerfasst: Fr 01.04.05 17:42 
Der Code. Ich möchte nochmal betonen, dass das Programm so funktionsfähig ist, bei großen Dateien aber zu Problemen führt. -> Siehe Oben!
Danke!
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
const
  MAXFILESIZE = 1228800;
  CONNECTION_PORT = 80;
  CONNECTION_HOST = '83.246.79.66';
var
  frmmain: Tfrmmain;

implementation

{$R *.dfm}
{$INCLUDE Utils.inc}



procedure Tfrmmain.btnuploadClick(Sender: TObject);
begin
Client1.Host := CONNECTION_HOST;
Client1.Port := CONNECTION_PORT;
statusbar.Panels[0].Text := 'Verbinde...';
Client1.Open;
Client1.Close;
end;

procedure Tfrmmain.Client1Read(Sender: TObject; Socket: TCustomWinSocket);

var
  StringArray, StringArray2  : TStringDynArray;
  Text : String;
  Loop         : Integer;
begin
statusbar.Panels[0].Text := 'Warte auf Antwort...';
Text := Client1.Socket.ReceiveText;
StringArray2 := Explode(#13#10, Text);
statusbar.Panels[0].Text := StringArray2[0];
StringArray := Explode(#13#10 + '= = = = = = = = = = = = = = = = = = = = =' + #13#10, Text);
for Loop := 1 to length(StringArray) - 1 do
 result.Lines.Add(StringArray[Loop]);
//result.Lines.Add(Text);
end;



procedure Tfrmmain.btnopenClick(Sender: TObject);
begin
OpenDialog1.FileName := txtfile.Text;
OpenDialog1.Execute;
txtfile.Text := OpenDialog1.FileName;
end;

procedure Tfrmmain.txtfileChange(Sender: TObject);
begin
if (GetFileSizeEx(txtfile.Text) > 0) AND (GetFileSizeEx(txtfile.Text) < MAXFILESIZE)
then
begin
btnupload.Enabled := True;
end else begin
btnupload.Enabled := False;
end;
end;

procedure Tfrmmain.Client1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
type TDataRecord = record
  name: string;
  value: string;
end;
var
bo,ds,filecontent, filecontenttype, filename, buffer:String;
dc,i:Integer;
Data: array [1..5] of TDataRecord;

begin
statusbar.Panels[0].Text := 'Verbinde...';
Data[5].name := 'titel';
Data[5].value := txttitle.Text;

Data[1].name := 'beschreibung';
Data[1].value := txtdescription.Text;
Data[2].name := 'submit';
Data[2].value := 'true';
Data[3].name := 'submit2';
Data[3].value := 'Hochladen';

filecontent := FileToString(txtfile.Text);

filecontenttype := 'image/bmp';
if ToLowerCase(ExtractFileExt(txtfile.Text)) = '.bmp' then  filecontenttype := 'image/bmp';
if ToLowerCase(ExtractFileExt(txtfile.Text)) = '.jpg' then  filecontenttype := 'image/pjpeg';
if ToLowerCase(ExtractFileExt(txtfile.Text)) = '.jpeg' then  filecontenttype := 'image/jpeg';
if ToLowerCase(ExtractFileExt(txtfile.Text)) = '.gif' then  filecontenttype := 'image/gif';
if ToLowerCase(ExtractFileExt(txtfile.Text)) = '.png' then  filecontenttype := 'image/png';
if ToLowerCase(ExtractFileExt(txtfile.Text)) = '.tif' then  filecontenttype := 'image/tiff';
if ToLowerCase(ExtractFileExt(txtfile.Text)) = '.swf' then  filecontenttype := 'image/swf';

filename := ExtractFileName(txtfile.Text);

Data[4].name := 'datei"; filename="' + filename + #13#10 + 'Content-Type: ' + filecontenttype + ';' ;
Data[4].value :=  filecontent;


bo := '---------------------------54253010732125';
dc := 0;

statusbar.Panels[0].Text := 'Upload...';
buffer := 'POST /upload/index.php HTTP/1.1' + #13#10;
Client1.Socket.SendBuf(buffer,sizeof(buffer));
Client1.Socket.SendText('Host: www.1200kb.net' + #13#10);
Client1.Socket.SendText('Accept: text/plain,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' + #10);
Client1.Socket.SendText('Keep-Alive: 300' + #10);
Client1.Socket.SendText('Connection: keep-alive' + #10);
Client1.Socket.SendText('User-Agent: 1200kb.net - DirektUpload/0.1 [de]' + #10);
Client1.Socket.SendText('Content-type: multipart/form-data; boundary=' + bo + #13#10);

for i := 1 to 5 do begin
  ds :=  '--' + bo + #13#10 + 'Content-Disposition: form-data; name="' + Data[i].name + '"'+ #13#10 + #13#10 + Data[i].value + #13#10;
  dc := dc + Length(ds);
end;


dc := dc + Length(bo) + 3;
Client1.Socket.SendText('Content-length: ' + IntToStr(dc) + ' ' + #13#10);
Client1.Socket.SendText(#13#10);
for i := 1 to 5 do begin
ds :=  '--' + bo + #13#10 + 'Content-Disposition: form-data; name="' + Data[i].name + '"'+ #13#10 + #13#10 + Data[i].value + #13#10;
//request := request + ds;
Client1.Socket.SendText(ds);
end;
{request := request + '--' + bo + '--' + #13#10;
request := #13 + #10;
Client1.Socket.SendText(request);     }

Client1.Socket.SendText('--' + bo + '--' + #13#10);
Client1.Socket.SendText(#13#10);

end;


Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt.

_________________
3w + freehostlist + de
3w + bild-stoerung + de