Reading Response Headers

Yes, it’s exactly what I want to do, I want to get that : 3d857f51/sessid=0z1F2tK2gjQAbw/9a8baoKCF . But I don’t know how to get the request header, that’s my problem :slight_smile: You say I have to iterate (for each) over the list of headers, but I don’t know how I can do it. Can you help me ?

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