UTF8 x UTF8EX (Httpd error ?)

206 views
Skip to first unread message

Vlad

unread,
Aug 30, 2020, 11:28:29 PM8/30/20
to Harbour Users
Hi Guys

I'm using hbhttpd contrib in my application and want shared my experience.

I attached zip with my tests.

Steps
First part
1. Run certo.bat to generate webserver 1.
2. In your browser, go to httpd://localhost:8003
3. See json content : {"Result":"OK","Field":{"codplano":"1.1.2","descricao":"REALIZAÇÕES","codpai":"1.1","___pk":"1.1.2"}}

Second part
1. Run errado.bat to generate web server 2 
2. Now, go to httpd://localhost:8002
3. See content :
{"Result":"OK","Field":{"codplano":"1.1.2","descricao":"REALIZAÇÕES","codpai":"1.1","___pk":"1.1.2"  <--- ERROR IN LAST CARACTERS 

Conclusions (partial)
1. In example 1. I using UTF8 : REQUEST HB_CODEPAGE_UTF8

2. In example 2. I using HB_CODEPAGE_UTF8EX

3. UTF8EX doesn't work correctly in samples.

4. UTF8EX is UTF8 with BOM (I suposed). BOM is extra caracters in begin of file. This feature cause error in last characters. 

5. Don't use UTF8EX in your projects with hbhttpd.

Question :

Could someone confirm these results, please?

thankful

Unfortunately I was unable to attach the examples. Only the images. 
** CODE WITH ERROR (UTF8EX) / FILE ENCODED TESTED WITH UTF8 AND UTF8 WITH BOM. To work fine, replace UTF8EX with UTF8.
#require "hbhttpd"

MEMVAR server, get, post, cookie, session /* These vars is not mandatory */
REQUEST HB_CODEPAGE_UTF8EX


/****************/
PROCEDURE Main

     LOCAL oServer, hConfig, hMount
     
     hb_CdpSelect("UTF8EX")

     IF hb_argCheck( "stop" )
          MemoWrit( ".uhttpd.stop", "" )
          RETURN
     ELSEIF hb_argCheck( "start" )
          ? "Init server in port 8002"
          ? "Please type localhost:8002 in your browser"
     ELSE
          ? "Usage: app [options]"
          ? "Options:"
          ? "  //start             Start server"
          ? "  //stop              Stop running server"
          RETURN
     ENDIF


     oServer := UHttpdNew()

     hMount := { => }
     hMount[ "/" ] := {|| Start() }

     hConfig := { ;
     "FirewallFilter"      => "", ;
     "Port"                => 8002, ;
     "Trace"               => {| ... | QOut( ... ) }, ;
     "Idle"                => {| o | iif( hb_vfExists( ".uhttpd.stop" ), ( hb_vfErase( ".uhttpd.stop" ), o:Stop() ), NIL ) }, ;
     "Mount"          => hMount }


     IF ! oServer:Run( hConfig )
          ? "Server error:", oServer:cError
          ErrorLevel( 1 )
          RETURN
     ENDIF


     RETURN


/***************/
FUNCTION Start()

    LOCAL cJson := '{"Result":"OK","Field":{"codplano":"1.1.2","descricao":"REALIZAÇÕES","codpai":"1.1","___pk":"1.1.2"}}'
    
    UAddHeader( "Content-Type" , 'application/json' )

    RETURN cJson
/***************/
 


ok.png
error.png

WenSheng

unread,
Sep 21, 2021, 10:19:24 PM9/21/21
to Harbour Users
/***************/
FUNCTION Start()

    LOCAL cJson := '{"Result":"OK","Field":{"codplano":"1.1.2","descricao":"REALIZAÇÕES","codpai":"1.1","___pk":"1.1.2"}}'
    
    UAddHeader( "Content-Type" , 'application/json' )

    RETURN cJson   <----- RETURN hb_utf8ToStr(cJson), It's OK!
/***************/

Vlad 在 2020年8月31日 星期一上午11:28:29 [UTC+8] 的信中寫道:

Vlad

unread,
Sep 22, 2021, 7:05:21 PM9/22/21
to Harbour Users
Hi  WenSheng

I tested but don't work. I will try send attached file. 

I solve this problem using UTF8 instead UTF8EX. 

hb_utf8ToStr doesn't solve this problem with UTF8EX.

Best regards

httpd01.prg

WenSheng

unread,
Sep 22, 2021, 9:22:31 PM9/22/21
to Harbour Users
a solution use tip_Urlencode(cJson) to return data of json.
and client use urldecode to decode data.


Vlad 在 2021年9月23日 星期四上午7:05:21 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages