GET request
- var s : String = "";
- def request : HttpRequest = HttpRequest {
- location: "http://javafx.com";
- onStarted: function() {
- s = "started"
- }
- onConnecting: function() {
- s = "{s}\nconnecting..."
- }
- onDoneConnect: function() {
- s = "{s}\ndoneConnect"
- }
- onReadingHeaders: function() {
- s = "{s}\nreadingHeaders..."
- }
- onResponseCode: function(code:Integer) {
- s = "{s}\nresponseCode: {code}"
- }
- onResponseMessage: function(msg:String) {
- s = "{s}\nresponseMessage: {msg}"
- }
- onResponseHeaders: function(headerNames: String[]) {
- s = "{s}\nthere are {headerNames.size()} response headers:";
- for (name in headerNames) {
- s = "{s}\n {name}: {request.getResponseHeaderValue(name)}"
- }
- }
- onToRead: function(bytes: Integer) {
- s = "{s}\nbytes to read: {bytes}"
- }
- onRead: function(bytes: Integer) {
- def progress =
- if (request.toread > 0) "({(bytes * 100 / request.toread)}%)" else "";
- s = "{s}\nbytes read: {bytes} {progress}";
- }
- onInput: function(is: java.io.InputStream) {
- try {
- s = "{s}\nbytes of content available: {is.available()}"
- } finally {
- is.close();
- }
- }
- onException: function(ex: Exception) {
- s = "exception: {ex.toString()}"
- }
- onDoneRead: function() {
- s = "{s}\ndoneRead"
- }
- onDone: function() {
- s = "{s}\ndone"
- }
- }
- Stage {
- title: "MyApp"
- scene: Scene {
- width: 400
- height: 600
- content:Text {
- font: Font {
- size: 11
- }
- x: 10,
- y: 30
- content: bind s
- }
- }
- }
- request.enqueue();
実行結果

variables
input : InputStream
location : "http://javafx.com"
method : String ("GET/POST/PUT/DELETE")
output : OutputStream (only POST or PUT)
POST : String (only method = POST)
PUT : String (only method = PUT)
read : Integer (read bytes)
responseCode : Integer
responseMessage : String
toread : Integer (be expected read bytes)
towrite : Integer (going to be written bytes)
written : Integer (have been written bytes)
triggers
onStarted: function() {}
onConnecting: function() {}
onDoneConnect: function() {}
onReadingHeaders: function() {}
onResponseCode: function(code:Integer) {}
onResponseMessage: function(msg:String) {}
onResponseHeaders: function(headerNames: String[]) {}
onToRead: function(bytes: Integer) {}
onRead: function(bytes: Integer) {}
// Be sure to close the input sream when finished
onInput: function(input: java.io.InputStream) {
try {
} finally {
is.close();
}
}
onException: function(ex: Exception) {}
onDoneRead: function() {}
onDone: function() {}
0 件のコメント:
コメントを投稿