"Invalid binary header" in TROWinInetHttpChannel when redirected

Hi,

I’m having trouble with the TROWinInetHTTPChannel.

If I set the TargetURL to a URL that redirects to another URL (302 - Temporary unavailable) I get an EROInvalidStream exception with message "Invalid binary header. Either incompatible or not a binary message.

<?xml version="1.0" encoding="utf-8"?>

.<
.<
.<
.<
.<
.<
.<
.<<Operatio" while transferring files to server “MY-URL”."

If i change the TargetURL to the URL that i previously was redirected to everything works fine.

Any clues about waht might go wrong when the request is being redirected?
It is obviously nothing wrong with the Server-Side since it works fine if I access it without being redirected.

Kind regards,

Hello,

Please, could you attach a simple testcase with redirecting url, reproducing error?

Best regards

Hi,

I have attached a simple testcase from Delphi XE using RO 6.0.49.861.

Kind regards,

Fredrik

Hello,

I’ve examined the testcase you attach. You should redirect request to ‘http://localhost:8099/bin’:

procedure TServerForm.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
AResponseInfo.Redirect(‘http://localhost:8099/bin’);
end;

Best regards

Sorry,
My mistake. I was just sloppy with the test case before I sent it.

I have of course tested with redirecting to ‘http://localhost:8099/bin’. It gives me the same exception.

Kind regards

Hello Fredrik,

Let me explain what’s going on there. Any HTTP remote service request is POST. When WinInet sees a redirect replied to POST it thinks about the Post/Redirect/Get pattern and issues a GET request to the received location. GET http://localhost:8099/bin gives us the server RODL back and this data is passed to RO as if it is a remote service response.
The problem here is we cannot affect WinInet (yes, it is “shut up, we know what you really need”). But we have other HTTP client channels available. I’d use Indy TROIndyHTTPChannel. It handles redirects properly after this property is set:

ROIndyHTTPChannel.IndyClient.HandleRedirects := true;

Best regards - Sergey.

Hi Sergey,

Thanks for your explanation.
I try to avoid TROWinInet components but in this case we have customers with old client-versions. I was hoping to avoid upgrading them. But in this case it seems as there is no workaround.

Kind regards,
Fredrik

Hello Fredrik,

Could you explain please why do you need those redirects? We could try to find another solution instead.

Best regards - Sergey.

Hi,

We are changing the URL for our service. And we will inform our customers that they need to change URL in their configuration.
But until they have change it we still want the old URL to work, being redirected to the new URL. We cannot just change the DNS records in this case.

Kind regards,

Hello Fredrik,

There is one more way to achieve the same: making a proxy server. Here is the sample. The only drawback here is you have to manually write a handler for every exposed method. But handlers are quite simple and it is feasible if the methods count is not too large.

Best regards - Sergey.

Thanks for the tip. I will look into it.

Kind regards,

Fredrik