How to transfer content RichViewEdit a POST request?

General TRichView support forum. Please post your questions here
Post Reply
sokoldok
Posts: 29
Joined: Sat Oct 26, 2013 9:27 pm

How to transfer content RichViewEdit a POST request?

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
sokoldok
Posts: 29
Joined: Sat Oct 26, 2013 9:27 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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?
sokoldok
Posts: 29
Joined: Sat Oct 26, 2013 9:27 pm

Post by sokoldok »

Вот сам сайт http://subscribe.ru/

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

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