Page 1 of 1

About Peeks a UTF8 html

Posted: Tue Jun 24, 2014 4:24 am
by shu7734
this is Mycode

Code: Select all

InitNetwork()  
  ConnectionID = OpenNetworkConnection("www.gov.cn",80) 
    String$="GET / HTTP/1.1"+#CRLF$
    String$=String$+"Accept:*/*"+#CRLF$
    String$=String$+"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; SV1)"+#CRLF$
    String$=String$+"Accept-Language:zh-cn"+#CRLF$
    String$=String$+"Connection:Keep-Alive"+#CRLF$
    String$=String$+"Host:www.gov.cn"+#CRLF$+#CRLF$
    Res = SendNetworkData(ConnectionID,@String$,Len(String$))  
  *Output=AllocateMemory(2048000)
  *Content = AllocateMemory(10240)
  count=0
  totallen=0
  While  count<5 
    Delay(100) 
    Result = NetworkClientEvent(ConnectionID)  
    Select Result  
        
    Case #PB_NetworkEvent_None
        count=count+1
        Delay(1000) 
   
    Case #PB_NetworkEvent_Data  
      
      recvLen=ReceiveNetworkData(ConnectionID,*Content,10240)  
      CopyMemory(*Content,*Output+totallen,recvLen)
      FillMemory(*Content,10240,0)
      totallen=totallen+recvLen
    Case #PB_NetworkEvent_Disconnect
      FreeMemory(*Content)
      CloseNetworkConnection(ConnectionID)
    EndSelect
  Wend

  CloseNetworkConnection(ConnectionID)
  Debug PeekS(*Output,-1,#PB_UTF8)
  
   FreeMemory(*Output)
Debug Output string

Code: Select all

<title>?????????????????</title>
the Memory is

Code: Select all

04780220  74 3D 55 54 46 2D 38 22 2F 3E 0A 3C 74 69 74 6C  t=UTF-8"/>.<titl
04780230  65 3E E4 B8 AD E5 8D 8E E4 BA BA E6 B0 91 E5 85  e>涓崕浜烘皯鍏
04780240  B1 E5 92 8C E5 9B BD E4 B8 AD E5 A4 AE E4 BA BA  卞拰鍥戒腑澶汉
04780250  E6 B0 91 E6 94 BF E5 BA 9C E9 97 A8 E6 88 B7 E7  姘戞斂搴滈棬鎴风
04780260  BD 91 E7 AB 99 3C 2F 74 69 74 6C 65 3E 0A 3C 6D  綉绔?/title>.<m
the IE souce code

Code: Select all

<title>中华人民共和国中央人民政府门户网站</title>

Re: About Peeks a UTF8 html

Posted: Tue Jun 24, 2014 5:51 am
by Danilo
Is this with Unicode compiler option enabled, and with PB 5.30 beta?
With < 5.30 beta, 'Debug' did not display Unicode chars. When compiled
with Unicode support, you could use MessageRequester instead Debug.

Re: About Peeks a UTF8 html

Posted: Tue Jun 24, 2014 6:03 am
by shu7734
Unicode compiler option is Disabled

memory view display utf8 is worked?
memory view show ???? too

pls send me a >5.3 beta download link.

thanks

Re: About Peeks a UTF8 html

Posted: Tue Jun 24, 2014 8:03 am
by netmaestro
pls send me a >5.3 beta download link.
Can't/won't happen. You have to buy PureBasic and become a registered user to get access.

Re: About Peeks a UTF8 html

Posted: Tue Jun 24, 2014 9:40 am
by Danilo
shu7734 wrote:Unicode compiler option is Disabled
Enable Unicode to see chinese chars.

The following works here. Unicode enabled, I see chinese characters in the MessageRequester.

Code: Select all

InitNetwork()  
  ConnectionID = OpenNetworkConnection("www.gov.cn",80) 
    String$="GET / HTTP/1.1"+#CRLF$
    String$=String$+"Accept:*/*"+#CRLF$
    String$=String$+"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; SV1)"+#CRLF$
    String$=String$+"Accept-Language:zh-cn"+#CRLF$
    String$=String$+"Connection:Keep-Alive"+#CRLF$
    String$=String$+"Host:www.gov.cn"+#CRLF$+#CRLF$
    ;Res = SendNetworkData(ConnectionID,@String$,Len(String$))
    Res = SendNetworkString(ConnectionID,String$)
  *Output=AllocateMemory(2048000)
  *Content = AllocateMemory(10240)
  count=0
  totallen=0
  While  count<5 
    Delay(100) 
    Result = NetworkClientEvent(ConnectionID)  
    Select Result  
        
    Case #PB_NetworkEvent_None
        count=count+1
        Delay(1000) 
   
    Case #PB_NetworkEvent_Data  
      
      recvLen=ReceiveNetworkData(ConnectionID,*Content,10240)  
      CopyMemory(*Content,*Output+totallen,recvLen)
      FillMemory(*Content,10240,0)
      totallen=totallen+recvLen
    Case #PB_NetworkEvent_Disconnect
      FreeMemory(*Content)
      CloseNetworkConnection(ConnectionID)
    EndSelect
  Wend

  CloseNetworkConnection(ConnectionID)
  Debug PeekS(*Output,-1,#PB_UTF8)
  MessageRequester("INFO",PeekS(*Output,-1,#PB_UTF8))
  
   FreeMemory(*Output)

Re: About Peeks a UTF8 html

Posted: Wed Jun 25, 2014 1:38 am
by electrochrisso
Nice example shu7734, I make a change to use the editor gadget instead for easier reading. :)

Code: Select all

CompilerIf #PB_Compiler_Unicode
CompilerElse
  MessageRequester("INFO","Set unicode exe, in Compiler Options")
  End
CompilerEndIf

InitNetwork()  
ConnectionID = OpenNetworkConnection("www.gov.cn",80) 
String$="GET / HTTP/1.1"+#CRLF$
String$=String$+"Accept:*/*"+#CRLF$
String$=String$+"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; SV1)"+#CRLF$
String$=String$+"Accept-Language:zh-cn"+#CRLF$
String$=String$+"Connection:Keep-Alive"+#CRLF$
String$=String$+"Host:www.gov.cn"+#CRLF$+#CRLF$
;Res = SendNetworkData(ConnectionID,@String$,Len(String$))
Res = SendNetworkString(ConnectionID,String$)
*Output=AllocateMemory(2048000)
*Content = AllocateMemory(10240)
count=0
totallen=0
While  count<5 
  Delay(100) 
  Result = NetworkClientEvent(ConnectionID)  
  Select Result  
      
    Case #PB_NetworkEvent_None
      count=count+1
      Delay(1000) 
      
    Case #PB_NetworkEvent_Data  
      
      recvLen=ReceiveNetworkData(ConnectionID,*Content,10240)  
      CopyMemory(*Content,*Output+totallen,recvLen)
      FillMemory(*Content,10240,0)
      totallen=totallen+recvLen
    Case #PB_NetworkEvent_Disconnect
      FreeMemory(*Content)
      CloseNetworkConnection(ConnectionID)
  EndSelect
Wend

CloseNetworkConnection(ConnectionID)
;Debug PeekS(*Output,-1,#PB_UTF8)
;MessageRequester("INFO",PeekS(*Output,-1,#PB_UTF8))
If OpenWindow(0,0,0,640,480,"EditorGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  EditorGadget(0,0,0,640,480,#PB_Editor_ReadOnly)
  SetGadgetText(0,PeekS(*Output,-1,#PB_UTF8))
  Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
FreeMemory(*Output)