Post IdHTTP with Delphi

3

I can make a post with HTML quietly, but when I try to do with Delphi, it presents me with this error:

  

link

Follow the code below:

function TForm1.UploadArquivo(server, script, caminhoarq : string) : boolean;
var
  Response : String;
  HTTPClient : TIdHTTP;
  Lista : TStringList;
begin
  result := False;
  HTTPClient := TidHTTP.Create;
  HTTPClient.ProtocolVersion := pv1_0;
  HTTPClient.Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
  HTTPClient.Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';
  Response := '';
  Lista := TStringList.Create;
  try
    try
      Lista.Add('Arquivo='+ caminhoarq);

      Response := Trim(HTTPClient.Post(server + script, Lista));
      Label1.Caption := Response;
      if Response = 'OK' then
        Result := true;
    finally
      Lista.Free;
      HTTPClient.free;
    end;
  except
    on e:exception do  ShowMessage('Erro ao enviar arquivo ao servidor! Detalhes: '+e.Message);
  end;
end;

Using Delphi XE7, is there any particularity?

What am I doing wrong?

    
asked by anonymous 18.11.2015 / 23:37

1 answer

3

This error can be because of the symbols, you should treat them before making the request!

HTTPClient := TidHTTP.Create;
HTTPClient.Request.ContentType := 'utf-8'; 

You can also try this:

Response := UTF8Decode(Trim(HTTPClient.Post(server + script, Lista)));

One more thing here:

HTTPClient.Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';

As amazing as it sounds, the "space" between there compatible and Indy Library might cause the same problem, then change to:

HTTPClient.Request.UserAgent := 'Mozilla/3.0 (compatible;Indy Library)';
    
19.11.2015 / 01:20