HTTP Request
HTTP Request
I am running the newest 1.5.0 release. I see that there is a http object. Is there any documentation on the http.request function? Does it support https?
-
- Posts: 3
- Joined: 18 Nov 2013 19:10
Re: HTTP Request
I found what I needed in the "Z-Way Developers Documentation". There is a section on JSON API that somewhat describes the HTTP interface. You could start there. It is also clear by inspecting the GUI code what some of the capabilities are.
I have no idea if that HTTP server supports HTTPS -- I set up a proxy in my environment.
I have no idea if that HTTP server supports HTTPS -- I set up a proxy in my environment.
Re: HTTP Request
The http.request is much like jQuery.ajax():
Here's the list of options:
Code: Select all
r = http.request(options);
- url – required. Url you want to request (might be http, https, or maybe even ftp);
- method – optional. Http method to use (currently one of GET, POST, HEAD). If not specified, GET is used;
- headers – optional. Object containing additional headers to pass to server:
Code: Select all
headers: { "Content-Type": "text/xml", "X-Requested-With": "RaZberry/1.5.0" }
- data – required for POST requests. Data to post to the server. May be either string (to post raw data) or an object with keys and values (will be serialized as "key1=value1&key2=value2&…");
- auth – optional. Provides credentials for basic authentication. It is an object containing login and password:
Code: Select all
auth: { login: "username", password: "secret" }
- contentType – optional. Allows to override content type returned by server for parsing data (see below);
- async – optional. Specifies whether request should be sent asynchronously. Default is false. In case of synchronous request result is returned immediately (as function return value), otherwise function exits immediately, and response is delivered later thru callbacks.
- success, error and complete – optional, valid only for async requests. Success callback is called after successful request, error is called on failure, complete is called nevertheless (even if success/error callback produces exception, so it is like "finally" statement);
- status – HTTP status code (or -1 if some non-HTTP error occurred). Status codes from 200 to 299 are considered success;
- statusText – status string;
- url – response url (might differ from url requested in case of server redirects);
- headers – object containing all the headers returned by server;
- contentType – content type returned by server;
- data – response data.
- application/json and text/x-json are returned as JSON object;
- application/xml and text/xml are returned as XML object;
- application/octet-stream is returned as binary ArrayBuffer;
- string is returned otherwise.
Re: HTTP Request
What are the arguments for the success, error, and complete callbacks?
Re: HTTP Request
All three have same parameter described above:
an object with status, statusText, url, headers, contentType and data properties.
an object with status, statusText, url, headers, contentType and data properties.
Re: HTTP Request
Hi All,
I want to create a HTTP request object in a module with the following code (using Razberry v.1.7.1)
My server checks if the content-type is set to "application/json" otherwise he will throw an error.
I sniffed the packets with Wireshark from ZWAY --> My Server and the result is: It seems to be that on a post request the headers with "Content-Type" : "application/json" will not correctly encoded. The same for "text/xml" . %2F in picture two is the URL-encoding value for /.
If it is correctly encoded, it would look like Can somebody reproduce the issue and maybe give a hint how to fix this?
I am also interest in using XMLHttpRequest Object(like request = new XMLHttpRequest(); ) and maybe modify the http.request() method (unfortunately I can´t find the method in .js files)
Thanks in advance for your responses!
I want to create a HTTP request object in a module with the following code (using Razberry v.1.7.1)
Code: Select all
http.request({
url: "IP TO MY SERVER",
method: "POST",
headers: {
"Content-Type" : "application/json"},
data: "",
});
I sniffed the packets with Wireshark from ZWAY --> My Server and the result is: It seems to be that on a post request the headers with "Content-Type" : "application/json" will not correctly encoded. The same for "text/xml" . %2F in picture two is the URL-encoding value for /.
If it is correctly encoded, it would look like Can somebody reproduce the issue and maybe give a hint how to fix this?
I am also interest in using XMLHttpRequest Object(like request = new XMLHttpRequest(); ) and maybe modify the http.request() method (unfortunately I can´t find the method in .js files)
Thanks in advance for your responses!
Using: Z-Way v2.0.1-rc11 on Raspberry Pi
Re: HTTP Request
RaZberry has it's own implementation. See in this post:I am also interest in using XMLHttpRequest Object(like request = new XMLHttpRequest(); )
viewtopic.php?f=3422&t=19972&hilit=+xml#p50960
Due to other things not working I haven't had the time to look into this.
Since 29-12-2016 I am no longer a moderator for this forum
Re: HTTP Request
We have an issue with URL-encodede Content-Type. This will be fixed soon,
Re: HTTP Request
Thanks for your answers, pz1 and PoltoS.
Would be kind to post here, if there are any news of the issue
I want to ask if it is possible to see the source code of http.request() function in z-way? I found only on automation/htdocs/js/helpers/apis.js the function request() and it is using jQuery (and I just thought jQuery is not available, when programming in backend - but maybe I am wrong and I can load it somehow )
I want to use XMLHttpRequest for all the communication (not only for sending and receiving xml) from ZWay --> MyServer instead of using http.request, like
Maybe there is a way how to use it in ZWay?
Thanks in advance for your responses!
Would be kind to post here, if there are any news of the issue
I want to ask if it is possible to see the source code of http.request() function in z-way? I found only on automation/htdocs/js/helpers/apis.js the function request() and it is using jQuery (and I just thought jQuery is not available, when programming in backend - but maybe I am wrong and I can load it somehow )
I want to use XMLHttpRequest for all the communication (not only for sending and receiving xml) from ZWay --> MyServer instead of using http.request, like
Code: Select all
var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
xmlhttp.open("POST", "/json-handler");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
Thanks in advance for your responses!
Using: Z-Way v2.0.1-rc11 on Raspberry Pi
Re: HTTP Request
don't mix client and server side.
automation/htdocs/* is client side UI for automation. And indeed it uses jQuery.
On server side it is not available. http.request code is our function, XMLHttpRequest is not available, as it is an extension of browsers.
automation/htdocs/* is client side UI for automation. And indeed it uses jQuery.
On server side it is not available. http.request code is our function, XMLHttpRequest is not available, as it is an extension of browsers.