[SOLVED] HttpRequest() What are the possible values for Flag

Just starting out? Need help? Post your questions and find answers here.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

[SOLVED] HttpRequest() What are the possible values for Flag

Post by Marc56us »

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.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HttpRequest() What are the possible values for Flag

Post by infratec »

A web site with accents:

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

:mrgreen: :mrgreen: :mrgreen:
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HttpRequest() What are the possible values for Flag

Post by infratec »

Code: Select all

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: Select all

Con = HTTPRequest(#PB_HTTP_Get, "https://www.purebasic.com/french/")
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: HttpRequest() What are the possible values for Flag

Post by Marc56us »

: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: Select all

            CreateJSON(0)
            ParseJSON(0, Reponse$)
            ShowLibraryViewer("json", 0)
            CallDebugger
            SaveJSON(0, Json_File$, #PB_JSON_PrettyPrint)
I'll look into it.
Thanks, guys.

:wink:
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HttpRequest() What are the possible values for Flag

Post by infratec »

Show me your Result$ from your HTTPRequest()

If it is correct, then the JSON stuff should not produce wrong characters.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: HttpRequest() What are the possible values for Flag

Post by Marc56us »

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:
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: [SOLVED] HttpRequest() What are the possible values for

Post by Bisonte »

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: Select all

  #PB_HTTP_Asynchronous: starts the download asynchronously.
  #PB_HTTP_NoRedirect  : don't follow automatic redirections.
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [SOLVED] HttpRequest() What are the possible values for

Post by infratec »

But only for HTTPRequest() and not for HTTPInfo() :wink:
Post Reply