Reading Response Headers

You have to work on the web response from the outside in,
saving intermediate results in global variables as stepping stones to help spot where you fail.

From the outside in, you have a JSONresponse object with tag “En-têtes de la réponse (223 o)” and value an object with headers a list under tag “headers”.
global responseTag global webResponse

I just tried both Web Jsondecode blocks on it, and got back empty texts, so we will have to fix the text, (On further inspection the JSON text you posted ended up with non-JSON slanty quotes, which need to be replaced with straight quotes.)
straighten

Here’s the meat …

and the proof:
Capture
and the .aia file:
JSON_headers.aia (4.5 KB)

Hello, thanks a lot for your work, but my problem is still not solved. You wrote into the variable “webResponse” directly the response, but I need to get it from the response header, updated each time I start the app. The cookie credentials I get is available only during 15 minutes. Can you tell me how I can get the header, without writing it into a variable ? Thank you

You would need some one who actually knows about http headers for that.
I only know about JSON parsing.

If the headers change at each run, ask for them in Screen1.Initialize.

P.S. What do you have against variables?

Hello,

I don't know if this will work for you ... in this discussion there is an extension called: com.KIO4_Terminal.aix

With this extension you can use many LINUX commands
Some devices have the curl command.
Can you test if this instruction works for you?
Terminal.Run
commandLine: curl -I https://www.keycdn.com

from Popular curl Examples - KeyCDN Support

Hello, everyone ! I think I haven’t explained well my problem. I want to perform a PUT request to a server to get a cookie credentials, which is in the header of the response. The PUT request works well on my program, I can send the request, and I get the body of the response. That’s my problem. I don’t know if it’s possible to get the response header in AppInventor, and if it is, tell me how to do it. Thank you.

try, if the extension from @Juan_Antonio can help...
the web component unfortunately does not provide a functionality to get response headers

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

Hello, this extension can’t work for me, I want something automatic, if I send commands, it won’t be the program I want :).

Does it return the headers ?

Other header response curl command examples:

curl -s -D - https://api.github.com/users | less
curl -i https://api.github.com/users | less
curl -IL http://bit.ly/in-the-shadows
curl -X HEAD -I http://httpbin.org/
curl -sSL -D - www.acooke.org -o /dev/null
curl -X POST http://httpbin.org/post -v > /dev/null
curl -X POST -sSL -D - www.acooke.org -v > /dev/null

Hello, I don’t know why you want I send curl commands, in my program I never sends curl commands.

It was you who asked me to curl the requested url, from my computer. But in my program, I never use curl.

Because the web component cannot return header responses from a server, instead you could possibly use Juan’s terminal extension to send a curl command instead, which might return the header responses you are after. You would need to have curl in your /system/bin for this to work.

well, the web component is not able to do what you want
your only option as far as I know is to try the extension as already mentioned together with the corresponding curl command
you might want to try it... it is your choice...

Taifun

I guess I'm having the same problem as you do @Crownir.
I need to read something in the "ResponsHeaders" as well as shown here

and for this reason (in 60 sec., the app can only fire 120 http-requests at their servers)

So I have installed your extension @Juan_Antonio ( well done, great job by the way :ok_hand: :+1:).
and played around with it a bit.
I've replace the all the commands in your "commands.txt" with only one line, being the curl command I need and uploaded the file again.
After I installed curl on my win10 computer, it worked just fine and I got the headers from curl.

So I tried that command in the emulator or your "Extension_Terminal" @Juan_Antonio , didn't work.
Compiled from the .aia and it didn't work either on my phone.
So I guess, as TIMAI2 says:

You would need to have curl in your /system/bin (on your phone) for this to work.

I've found this @Crownir:

https://www.xda-developers.com/mini-guide-to-install-curl-and-openssl-on-android/

if curl can be installed on the phone (if it's not already on it, that is) and in combination with the "KIO4_terminal" extension, the ResponsHeaders might be retrieveable.

It might be a work-around....

To bad the "Web" component can't be used directly to retrieve the ResponsHeaders.

Did you run the command on the extension that returns all the available commands ?

ls /system/bin

If you control the number of requests you make (to under 120 per minute) you should be OK, i can’t see a reason for needing these back from the server…

From your link:

NOTE: YOU MUST BE ROOTED WITH BUSYBOX INSTALLED TO INSTALL cURL

Yes, indeed, correct.
But when for example the app uses a “slider” to control the brightness of the lightbulb, it needs to be on the fly, sending each time a http-request.

Tried the “ls /system/bin” command, but came up empty, although “system” isn’t.
also tried the “curl --version”, which didn’t show anything.

EDIT: Guess the slider is off for the moment and as you’ve stated, I’ll control it myself.
Although I find the extension very usefull. See if I can play around with it, later on.

Hello E.V. , it is more convenient to work directly with the Terminal block

Hi there,

so, I don't know if it solves your problem, but I had a similar problem during working throught this great tutorial of METRIC RAT AI2 (see link below) and solved it with text manipulation.
Firebase with a web component
Saying in advance, my solution only works if the syntax of the response content is always the same (you need to proof that in advance!), therefore it's a little bit risky!

Here comes my solution:
I sent authentification data (should also work with PUT/PUSH/GET/DELETE into a database, just a different URL) into a Firebase console via a web-component.
I do not use the experimental Firebase tool, just pure URL-stuff.
Doing so I was able to read the responses via a programmed "set variable to response-content of the web-component"-function (don't know how it it's exactly called, look into the screenshots, you'll see what I mean).
Afterwards I read the strings of the variables, which contain the web-component responses and always have the same syntax.
Let the "starts at"-function search for the exact starting positions of key-headers before and after your content and add or subtract the numbers to the starting-/ending-position of your content.
It's a little bit of trial and error, that's why I displayed everything on the screen with labels, the pure response and my text-reading-results, to see which numbers work, but in the end it worked.
What I get as a result is the exact start and lenght of the content, so that I'm able to set variables to exact this content with the "segment"-function.
If you want to use those contents, you can easily join the contents into a URL to PUT/PUSH/GET/DELETE content in your database.

Edit: If for some reasons your database doesn't allow data-manipulation throught URL-requests, this solution will not work. Instead, you can use a Javascript file running on a server, which can be called with the webviewer component.