Ho un semplice script php sul mio server web che ho bisogno di caricare un file utilizzando HTTP POST, che sto facendo in Delphi.Post Http con indy
Ecco il mio codice con Indy ma in modo non funzionante non funzionerà e non riesco a capire cosa non sto facendo correttamente. Come posso visualizzare ciò che invio sul server: esiste un tale strumento?
procedure TForm1.btn1Click(Sender: TObject);
var
fname : string;
MS,dump : TMemoryStream;
http : TIdHTTP;
const
CRLF = #13#10;
begin
if PromptForFileName(fname,'','','','',false) then
begin
MS := TMemoryStream.Create();
MS.LoadFromFile(fname);
dump := TMemoryStream.Create();
http := TIdHTTP.Create();
http.Request.ContentType:='multipart/form-data;boundary =-----------------------------7cf87224d2020a';
fname := CRLF + '-----------------------------7cf87224d2020a' + CRLF + 'Content-Disposition: form-data; name=\"uploadedfile\";filename=\"test.png"' + CRLF;
dump.Write(fname[1],Length(fname));
dump.Write(MS.Memory^,MS.Size);
fname := CRLF + '-----------------------------7cf87224d2020a--' + CRLF;
dump.Write(fname[1],Length(fname));
ShowMessage(IntToStr(dump.Size));
MS.Clear;
try
http.Request.Method := 'POST';
http.Post('http://posttestserver.com/post.php',dump,MS);
ShowMessage(PAnsiChar(MS.Memory));
ShowMessage(IntToStr(http.ResponseCode));
except
ShowMessage('Could not bind socket');
end;
end;
end;
"Non funziona" è la frase meno utile possibile quando si esegue il debug di qualcosa. Cosa non funziona? Cosa fa di sbagliato? –
@MasonWheeler se conoscessi la risposta probabilmente non stavo facendo questa domanda. Non caricare sul server web il problema, suppongo che l'intestazione del post sia malformata, ma non so cosa sto facendo male. – opc0de
perché è MS.Clear; chiamato prima di http.Post (URL, MS)? – ComputerSaysNo