Post IdHTTP FIREMONKEY Delphi XE7

4

Follow the previous question:

Previous question on the same subject.

Now what it is showing is:

  

link

Code used:

Functional in VCL:

function TForm1.UploadArquivo(server, script, caminhoarq : string) : boolean;
var
  Response, UploadURL : String;
  HTTPClient : TIdHTTP;
  Lista : TIdMultiPartFormDataStream;
begin
  result := False;
  UploadURL := server + script;
  HTTPClient := TIdHTTP.Create;
  Lista := TIdMultiPartFormDataStream.Create;
  HTTPClient.ReadTimeout := 10000;
  HTTPClient.ProtocolVersion := pv1_1;
  HTTPClient.Request.ContentType := 'utf-8';
  HTTPClient.Request.UserAgent := 'Mozilla/3.0 (compatible;Indy Library)';
  HTTPClient.HTTPOptions := [hoForceEncodeParams,hoKeepOrigProtocol];
  Response := '';
  try
    try
      //Lista.Add('Arquivo='+ caminhoarq);
      Lista.AddFile('Arquivo', caminhoarq, 'application/octet-stream');
      Response := UTF8Decode(Trim(HTTPClient.Post(UploadURL, Lista)));
      //Label1.Text := Response;
      if Response = 'OK' then
        Result := true;
    except
      on e : exception do ShowMessage('Erro ao enviar arquivo ao servidor! Detalhes: '+e.Message);
    end;
  finally
    Lista.Free;
    HTTPClient.free;
  end;
end;

However, the site exists, and I have checked the string several times, and even then, it is displaying this message.

Now I'm testing firemonkey, the same code, because I believe it has not changed much, or even nothing.

Does anyone have an idea what's going on?

------------------ EDIT -----------------------

According to the debugs I've been doing, follow the comments:

In this line, the code for:

Response := UTF8Decode(Trim(HTTPClient.Post(UploadURL, Lista)));

Then I went deeper. In the function DoRequest .

When trying to connect to the Host, in the CheckAndConnect function, which is located inside the ConnectToHost function, it returns the error 404 located in Response .

But when I try to perform the same procedure on a VCL form. It works perfectly.

    
asked by anonymous 21.11.2015 / 15:10

1 answer

2

Gentlemen, I believe it was some string name conflict, because in my private I was using the name ScriptUP , after the change to the name ScriptUpload , he managed to get the Host, it seems that he does not have nothing to see, but honestly, it has!

Solution was to change the string that was capturing the host / script to perform post .

Follow the code:

function TForm1.UploadArquivo(server, script, caminhoarq : string) : boolean;
var
  Response, URL : String;
  HTTPClient : TIdHTTP;
  Lista : TIdMultiPartFormDataStream;
begin
  result := False;
  URL := server + script;
  Lista := TIdMultiPartFormDataStream.Create;
  HTTPClient := TIdHTTP.Create;
  HTTPClient.ProtocolVersion := pv1_1;
  HTTPClient.Request.ContentType := 'utf-8';
  HTTPClient.Request.UserAgent := 'Mozilla/3.0 (compatible;Indy Library)';
  HTTPClient.HTTPOptions := [hoForceEncodeParams, hoKeepOrigProtocol];
  Response := '';
  try
    try
      Lista.AddFormField('Arquivo', caminhoarq);//, 'application/octet-stream');
      Response := UTF8Decode(Trim(HTTPClient.Post(URL, Lista)));
      if Response = 'OK' then
        Result := true;
    except
      on e : exception do ShowMessage('Erro ao enviar arquivo ao servidor! Detalhes: '+e.Message);
    end;
  finally
    Lista.Free;
    HTTPClient.free;
  end;
end;
    
23.11.2015 / 23:36