Error uploading with IdHTTP firemonkey android

0

I'm using this code to do the tests uploading files to my server.

file html where I select the file.

<html>
<body> 
<form method="post" action="upload.php" enctype="multipart/form-data">
  <label>Arquivo</label>
  <input type="file" name="userfile" />
  <input type="submit" value="Enviar" />
</form>
</body>
</html>

and php uploading:

<?php
 $uploaddir = 'erro/';
 $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

 echo '<pre>';
 if   (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "Arquivo valido e enviado com sucesso.\n";
 }
 else {
    echo "Possivel ataque de upload de arquivo!\n";
 } 

 echo 'Aqui esta mais informacoes de debug:';
 print_r($_FILES);

 print "</pre>";
?>

This is working perfectly, but when I try to send some file by the application with the code below I get an error.

procedure export_erro;
var
    params: TIdMultipartFormDataStream;
    folder,resposta: string;
begin

    try

      folder:= 'storage/emulated/0/erros/';

        if not Directoryexists(folder) then
            forcedirectories(folder);

        if FileExists(folder+'aa.txt') then
        begin

            params := TIdMultiPartFormDataStream.Create;

            params.AddFile('userfile', folder+'aa.txt', 'text/plain');

            IdHTTP1.Request.CustomHeaders.Clear;
            IdHTTP1.Request.Clear;
            IdHTTP1.Request.ContentType := 'UTF-8';
            IdHTTP1.Request.ContentEncoding := 'multipart/form-data';

            resposta:= IdHTTP1.Post('http://site.com/upload.php', params);

        end
        else
            ShowMessage('arquivo não existe!');

    except on e:exception do
        ShowMessage(e.Message);
    end;

    FreeAndNil(params);

end.

The error is this

  

HTTP / 1.1 406 Not Acceptable

    
asked by anonymous 27.06.2018 / 22:51

1 answer

0

Error 406: Not acceptable . The requested resource is only able to generate content that is not acceptable according to the Accept headers sent in the request ( Link ).

content type problem. It can be some Mime Type that the server can not handle, invalid enciphering errors, etc.

    
27.06.2018 / 23:01