Post Idhttp FIREMONKEY Delphi XE7

Asked

Viewed 961 times

4

Following previous question:

Previous question on the same subject.

Now what he’s showing is:

http/1.1 404 Not Found.

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 checked the string several times, and yet, it keeps presenting this message.

Now I’m testing in firemonkey, the same code, because I believe that has not changed much, or even nothing.

Does anyone have any idea what’s going on?

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

According to the debugs I’ve been performing, follow the comments:

On this line, the code for:

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

So I went deeper. In function DoRequest.

When trying to connect with Host, in function CheckAndConnect, which is situated within the function ConnectToHost it returns the 404 error in Response.

But when I try to do the same in a VCL form. It works perfectly.

  • Post the codes so we can see!

  • Those are the ones on the link!

  • Good afternoon Ramon, I recommend you to make intuitive titles, the title of the two questions is practically the same and does not refer to the problem of the question.

  • @Guilhermenascimento, Good afternoon! I think that was the point, because everything is the same when I did for VCL, what changes is that the previous error is Solved, and the present only in FIREMONKEY.

  • @Guilhermenascimento no idea of what might be?

  • @Júniormoreira Some expensive idea?

  • @Ramonruan, do this, from a Breack in this line Response := Utf8decode(Trim(Httpclient.Post(Uploadurl, List)); put the mouse over it and see if it’s okay! If you write it down and put it here!

  • I will post in the question the results.

  • @Júniormoreira follows comments on debug, to be more direct, he is returning the exception right away, while trying to perform the post.

  • I wanted you to give a breackpoint right there where I said Saka, put the mouse on, press F8 once, it will follow the line, put the mouse on the variable "Response" and see what she received!

  • She gets nothing! precisely because of Error!

  • @Ramonruan, remove the Utf8decode that is going to Response, leave as you were using before, if it does not work, we will have to go to another approach!

  • @Juniors, same thing!!

  • @Ramonruan, I’d have to see the whole project, it’s unfeasible for you to post the project here. If you want we can make contact outside the OS, when we arrive at a solution we post here!

  • Thank you Junior!

Show 10 more comments

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 got the Host, it looks like it has nothing to do with it, but honestly, it has!

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

Follows 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.