Reading AJAX/JSON Responses in Linux (Bash/Perl/PHP)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Reading AJAX/JSON Responses in Linux (Bash/Perl/PHP)
I commonly use curl or wget in a RHEL5.6 Bash environment; however, a recent request has stumped me.
The web server I am sending a http request to is sending an initial response object, then multiple subsequent .js files after the end of the response object. The ongoing server pushes are all .js files and continually come. Obviously curl and wget only send a request and listen for a response - nothing past that.
I am looking for a way, whether it be Shell Script, Perl, PHP, or really any linux-based solution to receive these ongoing responses and place them into flat files for parsing.
The files all appear to be JSON objects of data.
I interrogated the header of these server pushes and the header look like the following:
Code:
X-Varnish 791943621
Content-Type text/javascript; charset=ISO-8859-1
Age 0
Via 1.1 varnish
Expires Tue, 15 May 2012 18:04:39 GMT
Date Tue, 15 May 2012 17:04:39 GMT
Server Jetty
Content-Length 3505
Connection keep-alive
Cache-Control PUBLIC, max-age=3600
Any feedback, suggestions, or information would be greatly appreciated. Without simply watching the data update in a browser I am having difficulties finding a shell-based solution to retrieve this data.
The initial response is standard HTML/Javascript. The multiple subsequent responses I can only "catch" and view right now if I use a debugging tool; however, it is 100% javascript:
In typing this, I guess there is a chance that the initial response is making subsequent request calls via javascript too. Maybe I should look into seeing if subsequent ajax requests are being done behind the scenes.
I know when you go to the page in a web browser the page loads, then data is continually refreshed/updated. Obviously when in a shell environment, using curl or wget, all I see is the html of the initial response and not all the subsequent data. I am trying to figure out how to get this data in a programatic fashion.
That makes sense now - I think I was trying to make this more magical than it is. What must be happening is the initial response begins a polling session sending subsequent requests to get data. Thus, after the initial response is received ongoing request/responses are occurring. I just need to figure out the subsequent responses and duplicate them.
If you visit the site using Chrome or Firefox you should be able to view what is happening between the browser and the server using the
Developer Tools or Javascript Console.
wrench icon -> Tools -> Javascript Console, pick the Network tab and you will see what requests the browser is sending.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.