HTTP/1.1 406 Not Acceptable with Delphi and PHP

  

I have a simples IdHTTP.Get() to get a file contents, and IdHTTP.Post() to send a file via param, that I used with Delphi 2006. It worked like very well and fast. The first version was via IdFTP and it was very slow.

Now I copied that code to an Android App with XE8 and I get the error

http1.1-406-not-acceptable

when I try to upload the file. The download via Get() is ok. It seems that the problem is with the response of the post, but I think it should at least finish sending the file, but does not.

IdHTTP.pas where the program breaks when I run it in Win32:

case FHTTPProto.ProcessResponse(AIgnoreReplies) of
wnAuthRequest:
begin
Request.URL := AURL;
end;
wnReadAndGo:
begin
ReadResult(Request, Response);
if Assigned(AResponseContent) then begin
AResponseContent.Position := LResponseLocation;
AResponseContent.Size := LResponseLocation;
end;
FAuthRetries := 0;
FAuthProxyRetries := 0;
end;
wnGoToURL:
begin
if Assigned(AResponseContent) then begin
AResponseContent.Position := LResponseLocation;
AResponseContent.Size := LResponseLocation;
end;
FAuthRetries := 0;
FAuthProxyRetries := 0;
end;
wnJustExit:
begin
Break;
end;
wnDontKnow:
begin
raise EIdException.Create(RSHTTPNotAcceptable);
end;
end;
until False;

I think, by reading your responses to other users questions about Indy, is that something is wrong with Encoding. But I confess I am very noob at this (did not needed to study encoding types until now) and do not understand the Delphi changes in this matter. Please help me! I don’t want to use FTP again.

My Code inside of the try-except in the thread (i suppressed some URL part):

Params := TIdMultipartFormDataStream.Create;
Params.AddFile(‘dc’,FilesPath+FileName));
webRequest := TIdHttp.Create;
webRequest.ConnectTimeout := 0;
webRequest.ReadTimeout := 0;
SaveCheck := webRequest.Post(‘http://alcantara.net.br/ristretto/?ac=ul’, Params);
ShowMessage(SaveCheck);
Params.Free;
aStream.Free;
webRequest.Free;

Inside my hostgator server with download and upload code, it works when I test from the browser:

if ((isset($_REQUEST[‘ac’])) && ($_REQUEST[‘ac’]==’dl’))
{
$LoginNX = @$_REQUEST[‘ln’];
$LoginKX = @$_REQUEST[‘lk’];
$DocumentNX = @$_REQUEST[‘dn’];
$DocumentKX = @$_REQUEST[‘dk’];
$FileName = md5($LoginNX.$LoginKX.$DocumentNX.$DocumentKX);
if (file_exists($FileName))
{
echo file_get_contents($FileName);
}
else
{
echo ‘@newdoc’;
}
}

if ((isset($_REQUEST[‘ac’])) && ($_REQUEST[‘ac’]==’ul’))
{
$LoginNX = @$_REQUEST[‘ln’];
$LoginKX = @$_REQUEST[‘lk’];
$DocumentNX = @$_REQUEST[‘dn’];
$DocumentKX = @$_REQUEST[‘dk’];
$Document = @$_REQUEST[‘dc’];
$FileName = md5($LoginNX.$LoginKX.$DocumentNX.$DocumentKX);
try
{
//file_put_contents($FileName, $Document);
if (move_uploaded_file($_FILES[‘dc’][‘tmp_name’], $FileName) === false)
{
echo ‘Erro: arquivo inválido!’;
}
else
{
echo ‘@finish’;
}
}
catch (Exception $error)
{
echo ‘Erro :’ . $error->getMessage();
}
}

The goal is to make a text editor that stores the files in cloud to avoid loss when loose cellphone or phone reset, but a plus is that it is cyphered with rca with keys not stored in the cloud.

Comments are closed.