UIAHost Request example with json - javascript

has someone any ideas, how can i make a request with UI Automation and JS with UIAHost. An example is welcome with POST as method, some data and json as datatyp.
Thank

The easiest way to make an HTTP request via UIAutomation would be to make a cURL request via the shell using performTaskWithPathArgumentsTimeout.
If you are making a POST request with a lot of data, you may want the shell command to read the data from disk (instead of specifying it all on the command line). Our Illuminator project provides a function that lets you write arbitrarily large files to disk from within UIAutomation.

Related

can AJAX do anything else than load a JSON file?

I'm want to (or think I need to) use AJAX to accomplish what I intend.
When clicking on a specific link in a list of links, I want to fill the HTML markup below with content of specific subpages. The data is naturally somewhere in the database and actually easily accessible with the CMS's API (I'm using Processwire).
I'm quite new to coding and especially AJAX and all documentation I find online only mention it in combination with a JSON file that would be loaded via AJAX.
However, I don't have a JSON file on the server, that means, according to my understanding, I would need to
store the data I need in a multidimensional php array,
use json_decode to create and then save that JSON-file on the server,
load that file via AJAX and process through more JS.
Let alone keep that JSON-file updated (or create a new one and delete the old one?) since new content will arrive periodically. It seems unnecessarily complicated to me, but what do I know.
There's got to be a better way…
Any help is appreciated.
AJAX is simply a way to make a request to the web server for information.
When you make an AJAX request you ask for a response from a file on a server. So, you can send an AJAX request to a PHP script for-instance.
The PHP script could return anything, JSON is common and very widely used response format, but XML might be another one you've encountered.
So, your request for information is made using AJAX, and the response you get back is JSON.
You don't need to store a JSON file on your server. You just need to make an AJAX request that returns current data in JSON format.
AJAX allows you to do asynchronous HTTP requests.
You can of course ask for a json file, but you can also (for example) call an API.
I suggest you start by reading the the getting started guide for AJAX in MDN:
https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started

How to extract a JavaScript fetched information with Requests module?

I need two informations to generate the url to send the POST request to the server: api_token and cid, as you can see in the JS code bellow:
// Run query
fetch(`/ajax/gw-light.php?api_version=1.0&api_token=${encodeURIComponent(config.get('checkForm'))}&input=3&cid=${cid || id}`
I can get the token by parsing the HTML, but the 'cid' is fetched by functions in JavaScript. Is there any way to get this only by Requests?
I know about Selenium, but its very very slow. Requests goes directly to the point.
You cannot do this with Python Requests, you will need to look to use a headless browser as Python Requests does not execute JavaScript. You may be able to see where this code is being executed, for example... if there is an api call being made to get this token, than you could replicate it with Python Requests.
The bottom line is Python Requests and BeautifulSoup do not execute JavaScript it's simply HTTP and not a browser JS engine.

sending local mp3 file to api server using jquery

I wish to use echoprint - http://echoprint.me/start - which allows me to send an mp3 file locally from my computer in a post request, and returns a json object including the song's details from their server.
I am attempting to make this post request using jquery in order to allow me retrieve the json object containing the song details, which will then allow me view this in my browser's console.
The echoprint website - http://developer.echonest.com/docs/v4/track.html - explains how to make this post request using curl. The following code works in the command line. This returns a json object, however this gets returned in the terminal.
curl -F "api_key=#############" -F "filetype=mp3" -F "track=#tambourineMan.mp3" "http://developer.echonest.com/api/v4/track/upload"
I have read the curl docs http://curl.haxx.se/docs/httpscripting.html#POST to try and understand where the correlation exists between the curl and jquery, but unfortunately I am having difficulties relating the two and understanding what -F means.
My aim is to make this post request using jquery so I can make the same request as outlined using curl above, and retrieve the json data in the browser's console.
From a previous question I asked on here I have tried to adopt the logic from that answer and used the following code, however this returns an error that the file cannot be encoded. I have tried it with and without the content type specified, but both methods fail.
$.post("http://developer.echonest.com/api/v4/track/upload", {
"api_key":"##################",
"track":"#tambourineMan.mp3",
"filetype":"mp3",
"contentType:" "application/octet-stream"
},
function( data ) {
console.log(data)
},
"JSON" );
There are instructions here http://developer.echonest.com/docs/v4/track.html but they only explain how to do this using curl. If anyone could shed any light on this it would be greatly appreciated. Pardon my ignorance in advance.
cURL uses the # prefix to mean "the contents of the named file", in your AJAX request you are sending #tambourineMan.mp3 as a literal string.
One easy to way to accomplish your task is to put a file input in your document and tell jQuery to use the data from that file:
var file = document.getElementById('myFileInput').files[0];
$.post("http://developer.echonest.com/api/v4/track/upload", {
"api_key":"##################",
"track":file,
"filetype":"mp3",
"contentType:" "application/octet-stream"
});
Take a look at the FileReader API and at this article about sending and receiving binary data in a XMLHttpRequest

How can i simulate REST post request with json data in browser

I have the web application where the frontend is in ExtJS and backend is in PHP.
The forms are build in Extjs and its making PUT and POST request to server for saving data.
The josn data is posted like this
{"id":"101","description":"user1","active":true}
Now for debugging i would like to directly call this URL in browser so that i can use var_dump for helpful messages.
As the request is AJAX by Extjs , so its very difficult to see messages through firebug.
Is there any way to make this request from browser and see response in rendred html.
I don't want to make form.
If you are using Google Chrome you can use the Postman Extension. It allows you to send pretty much any type of data and see the results.
For firefox you can use restclient plugin. Its also very easy to use, and userfriendly.
Also, if you know curl, you can do it programatically from PHP.
If the requests being made through a store in extjs, you can use Ext.getStore to find the store and create global variable. Then you could manipulate this global variable in the console.
i.e. write following in console
var s = Ext.getStore('myStore')
then after firing you can now manipulate this global in console
s.proxy.extraParams.myChangedValue = 'newValue'
s.load()
The response from the server will be in the network panel in chrome browser or use firebug extension for firefox. You can also add a callback or listener to the load event to console.log() what was parsed by the framework.
Another alternative is the Chrome's Advanced REST Client App. It isn't as powerful as the postman extension but I think it is a little bit easier to use.
If you are on good terms with curl you can just use it directly with -d (--data) option like that:
curl -X GET -H "Content-Type: application/json" -d #data.json localhost:8080/path/to.json
Where data.json is a JSON file.
Anyway, representation of an extension might be more intuitive and readable.

Read/write json from js to file on server (not server app)

I'm working with a .js client and have and object that I need to write out to a file on the server. A couple of questions - file i/o with JavaScript is new to me... I was planning on using jquery and json. I'm using java serverside. I don't have a problem reading what I get back from my servlet, but the file i/o is killing me! A couple of questions:
I can open a file I generated myself via the .js with an $.ajax call, but it's not handling my json syntax (I tried both an $.getJson and $.ajax - handwritten json, so I might (probably) are doing something wrong with it). I used firebug's console and it looks ok...
How can I write my object to a file on the server?
Then, when I want to read it, what do I need to do to process it? Right now I'm using a jsonFilter function (uses JSON.parse if that's available, otherwise eval) to process data that I'm getting from the servlet.
The object I'm writing isn't simple, but it's not super complex either. There's an array that contains an array, but that shouldn't make a difference if the software is both reading/writing it.
Thanks for any help! I'm at a loss - tried alot of different things.
You can open a file located on the server via ajax by querying the file and loading it into a JSON object. You might want to LINT your JSON
You can not write to an object on the server via the client. This is a severe security breach.
Common practice is to change the JSON data and then send it via ajax to server-side code. The server will then do the file IO.
Yes using JSON.parse otherwise eval is indeed correct. I would recommend json2.js
The data should be fine as long as it passes JSONLint.
Your main issue is that it's impossible to write to the server from the client. Get the client to load the data through ajax change it and then query the server to update the file.
js don't have i/o property;
you should use ajax or http request to send message to server,and tell server to do de i/o action...

Categories

Resources