Forum > Networking and Web Programming
[Solved] Sending Binary data using TFPHTTPServer and POST
(1/1)
Amir61:
Hi all,
I am trying to send some binary data using TFPHTTPServer and POST. Here is the snippet of my code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TMyServer.HandleRequest(var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse);...begin Request := TRequestMessage.Create(AReqeust) Response := TResponseMessage.Create; Self.ServeRequest(ARequest, Request, Response); BinData := ''; Response.SaveAsBinary(BinData); AResponse.ContentType := 'application/octet-stream'; AResponse.ContentLength:= Length(BinData); AResponse.Content := BinData; ... end; I noticed that the data I send and receive are different. After some more debugging, I figured out that the content of my "BinData" variable and AResponse.Content are different:
For example, if BinData is #10#13#78#111, the value stored in AResponse.Content would be #10#10#78#111.
I wonder if the issue is because of the ContentType? What ContentType should I use?
Amir61:
Looks like the following works:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TMyServer.HandleRequest(var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse);...begin Request := TRequestMessage.Create(AReqeust) Response := TResponseMessage.Create; Self.ServeRequest(ARequest, Request, Response); BinData := ''; Response.SaveAsBinary(BinData); AResponse.ContentType := 'text/html'; OutputStream := TStringStream.Create(BinData); AResponse.ContentStreeam := OutputStream; ... end;
Navigation
[0] Message Index