Page 1 of 1

How to transfer content RichViewEdit a POST request?

Posted: Mon Oct 28, 2013 10:06 pm
by sokoldok
Hello!

How to transfer content RichViewEdit a POST request? Now I do so, first save the contents Richviewedit in HTML using RichViewEdit1.InsertStringTag ('','');
RichViewEdit1.SaveHTMLEx ('tekst.html','', 'IMG','','','', [rvsoImageSizes, rvsoUseCheckpointsNames]);

then cut out of tekst.html extra characters, the main text with html tags that I need to save a variable and then pass that variable is a POST request. I'm new to the forum and even with kampanentom work recently, help me understand, maybe it is implemented as it is easier?

Apologies for the rough translation, translate through translate.google.ru as the English do not own, native language is Russian. Maybe there compatriots here?

Posted: Tue Oct 29, 2013 8:28 am
by Sergey Tkachenko
How to save HTML to AnsiString in UTF-8 encoding

Code: Select all

function GetHTMLAsString(rv: TCustomRichView): AnsiString;
var Stream: TMemoryStream;
begin
  Stream :=  TMemoryStream.Create;
  try
    rv.SaveHTMLToStreamEx (Stream, '', '', 'IMG','','','', [rvsoImageSizes, rvsoUseCheckpointsNames, rvsoUTF8]);
    Stream.Position := 0;
    SetLength(Result, Stream.Size);
    Stream.ReadBuffer(PAnsiChar(Result)^, Length(Result));
  finally
    Stream.Free;
  end;
end;
Next, data in POST must be URL-encoded.
A function for encoding is like this:

Code: Select all

uses RVTypes;
function EncodeURL(const s: AnsiString): AnsiString;
var i: Integer;
    s2: AnsiString;
begin
  Result := s;
  for i := Length(Result) downto 1 do
    if (ord(Result[i])<128) and (TRVAnsiChar(Result[i]) in
      ['%', '<', '>', '"', '&', #13, #10, ' ', '+']) then begin
      s2 := RVIntToHex(ord(Result[i]), 2);
      Result[i] := '%';
      Insert(s2, Result, i+1);
    end;
end;
The next question is images. By default, they are saved as files. There is a way to embed them directly in <img src>: http://en.wikipedia.org/wiki/Data_URI_scheme
In TRichView, it is possible to implement it using OnSaveImage2 event.
(I'll consider implementing it as a built-in feature in the next update)

Posted: Tue Oct 29, 2013 8:35 am
by Sergey Tkachenko
You can post questions in Russian on this forum: http://www.trichview.com/forums/viewforum.php?f=9
(it is available for Russian registered users)

Posted: Tue Oct 29, 2013 1:12 pm
by sokoldok
Thank you very much, Sergey Tkachenko. Half of the planned managed to implement, but with the transfer through POST and saving encoding through EncodeURL problems, Cyrillic is not displayed properly.

Posted: Tue Oct 29, 2013 2:13 pm
by Sergey Tkachenko
I included rvsoUTF8 in the Options of SaveHTMLToStreamEx, so this HTML has UTF-8 encoding.
Does the side that receive these data understand that this HTML is UTF8-encoded?

Posted: Tue Oct 29, 2013 3:32 pm
by sokoldok
Вот сам сайт http://subscribe.ru/

Ответ сервера:
Response Headers: text/plain; charset=utf-8

Вот что у меня получается на выходе http://www.trichview.com/forums/viewtopic.php?t=6167