It is currently Sun Dec 16, 2018 6:25 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: [SOLVED] HttpRequest() What are the possible values for Flag
PostPosted: Tue Nov 06, 2018 5:56 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 528
Hi all,

The new command HTTPRequest is not yet documented,
however when used, the IDE status bar displays:

HTTPRequest(Type, URL$ [, Data$ [, Flags [, Headers()]]]) - Executes an HTTP request.
What are the possible values for Flag ? All examples put 0

I ask this because I am testing a WebService in French and whose accents in return do not pass with HTTPRequest
But:
- Accents are OK well in a browser (Firefox)
- Accents are OK with a ReceiveHTTPFile()

I used the header "Header$("Accept-Language") = "fr_FR"" as indicated in the webservice provider documentation.
The emitted data in return are in UTF-8.
The file created by SaveJson is in UTF-8

But in reply:
è => è
ô => ô

I also created a header identical to the one used by Firefox, but without any effect.

There are not many accented characters, so I can change them afterwards, but I would like to know if this can be solved with the fourth undocumented parameter ?
PS. If someone had the URL of a public webservice returning data with accents, I would be interested to be able to make a comparison. (I can't post my current test URL because access is limited.)

:wink:


Last edited by Marc56us on Wed Nov 07, 2018 11:24 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: HttpRequest() What are the possible values for Flag
PostPosted: Tue Nov 06, 2018 6:09 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4051
Location: Germany
A web site with accents:

https://www.purebasic.com/french/

:mrgreen: :mrgreen: :mrgreen:


Top
 Profile  
Reply with quote  
 Post subject: Re: HttpRequest() What are the possible values for Flag
PostPosted: Tue Nov 06, 2018 6:13 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4051
Location: Germany
Code:
Con = HTTPRequest(#PB_HTTP_Get, "https://www.purebasic.com/french/", "", #PB_UTF8)
If Con
  Response$ = HTTPInfo(Con, #PB_HTTP_Response)
  Debug Response$
EndIf


But you don't need the Flag, because UTF8 is the default value.

Works also:
Code:
Con = HTTPRequest(#PB_HTTP_Get, "https://www.purebasic.com/french/")


Top
 Profile  
Reply with quote  
 Post subject: Re: HttpRequest() What are the possible values for Flag
PostPosted: Tue Nov 06, 2018 6:20 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 528
:o :mrgreen:
You're right, and it works for accents, with or without #PB_UTF8, so the problem is elsewhere

My webservice use JSON in reply, so CreateJSON()?, ParseJSON() or SaveJSON()

ShowLibraryViewer("json", 0) show wrongs accents, so error is not in SaveJson()

Code:
            CreateJSON(0)
            ParseJSON(0, Reponse$)
            ShowLibraryViewer("json", 0)
            CallDebugger
            SaveJSON(0, Json_File$, #PB_JSON_PrettyPrint)

I'll look into it.
Thanks, guys.

:wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: HttpRequest() What are the possible values for Flag
PostPosted: Tue Nov 06, 2018 8:20 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4051
Location: Germany
Show me your Result$ from your HTTPRequest()

If it is correct, then the JSON stuff should not produce wrong characters.


Top
 Profile  
Reply with quote  
 Post subject: Re: HttpRequest() What are the possible values for Flag
PostPosted: Wed Nov 07, 2018 11:23 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 528
Found :!: :P

This is HTTPInfo() who need flag #PB_UTF8 (for accents), even if reply is send as Utf-8

Protected Reponse$ = HTTPInfo(HTTPRequest, #PB_HTTP_Response, #PB_UTF8)

:wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] HttpRequest() What are the possible values for
PostPosted: Wed Nov 07, 2018 8:20 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1002
In another post, Fred says, that the flags are the same like ReceiveHTTPFile...
so that have nothing to do with UTF8 or something like that.

Code:
  #PB_HTTP_Asynchronous: starts the download asynchronously.
  #PB_HTTP_NoRedirect  : don't follow automatic redirections.

_________________
PureBasic 5.46 LTS / 5.62 (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] HttpRequest() What are the possible values for
PostPosted: Wed Nov 07, 2018 8:57 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4051
Location: Germany
But only for HTTPRequest() and not for HTTPInfo() :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] HttpRequest() What are the possible values for
PostPosted: Thu Nov 08, 2018 12:00 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 528
Yes, this is HttpInfo() who need #PB_UTF8 as flag.

From what I discovered (but I may be wrong ?)
By default, HTTPInfo does not decode in Utf-8, even if the server sends its data in Utf-8.
So you have to put the parameter. (no defaut parameter set as #PB_UTF8 Unlike other commands.)

Example to illustrate.
Launch the server and then the client

WS_Server.pb
Code:
EnableExplicit

InitNetwork()

Define Port = 80
Define *Buffer = AllocateMemory(1000)

If Not CreateNetworkServer(0, Port)
    Debug "Server Ready (Port " + Port + ")"
    MessageRequester("Error", "Can't create server (port in use ?)", 0)
    End
EndIf

Debug "Server Listening. "
Define SEvent, ClientID
Repeat       
    SEvent = NetworkServerEvent()
    If SEvent
        ClientID = EventClient()
        Select SEvent
               
            Case #PB_NetworkEvent_Connect
                Debug "New client connected"
               
            Case #PB_NetworkEvent_Data
                Debug ~"Client " + Str(ClientID) + " has sent data."
                ReceiveNetworkData(ClientID, *Buffer, 1000)
                Debug "Datas: " + PeekS(*Buffer, -1, #PB_UTF8)
                Define Reply = SendNetworkString(ClientID, ~"{\"Caractères accentués\": \"é è à\"}", #PB_UTF8)
                Debug "Bytes returned for " + ClientID + " " + Reply
                CloseNetworkConnection(ClientID)
               
            Case #PB_NetworkEvent_Disconnect
                Define Quit = 1
               
        EndSelect
    EndIf   
Until Quit = 1

CloseNetworkServer(0)
Debug "OK Done. Connections Closed."

End   


WS_Client.pb
Code:
EnableExplicit

InitNetwork()

NewMap Header$()
Header$("ContentType") = "octectstream"
Header$("UserAgent") = "Firefox 54.0"
Header$("NoParamHeader") = ""

Define HR = HTTPRequest(#PB_HTTP_Get, "http://127.0.0.1", "", 0, Header$())
If HR
    Debug "HTTPInfo without Flag  : " + HTTPInfo(HR, #PB_HTTP_Response)
    FinishHTTP(HR)
Else
    Debug "Erreur HR"
EndIf

Debug ""

HR = HTTPRequest(#PB_HTTP_Get, "http://127.0.0.1", "", 0, Header$())
If HR
    Debug "HTTPInfo with #PB_UTF8 : " + HTTPInfo(HR, #PB_HTTP_Response, #PB_UTF8)
    FinishHTTP(HR)
Else
    Debug "Erreur HR"
EndIf

End

Output (Client)
Code:
HTTPInfo without Flag  : {"Caractères accentués": "é è à"}

HTTPInfo with #PB_UTF8 : {"Caractères accentués": "é è à"}

:wink:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: DarkDragon, Kwai chang caine and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye