* Implement get/setBinaryMode(boolean) to allow delivery of the
response body as byte array instead of as string. * Use OutputStreamWriter instead of DataOutputStream for writing the request body.
This commit is contained in:
parent
e36bbce6d3
commit
602f420f18
1 changed files with 25 additions and 8 deletions
|
@ -8,10 +8,10 @@
|
||||||
*
|
*
|
||||||
* Copyright 1998-2006 Helma Software. All Rights Reserved.
|
* Copyright 1998-2006 Helma Software. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* $RCSfile: helma.Http.js,v $
|
* $RCSfile: Http.js,v $
|
||||||
* $Author: czv $
|
* $Author: czv $
|
||||||
* $Revision: 1.11 $
|
* $Revision: 1.2 $
|
||||||
* $Date: 2006/04/18 13:06:58 $
|
* $Date: 2006/04/24 07:02:17 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ helma.Http = function() {
|
||||||
var method = "GET";
|
var method = "GET";
|
||||||
var credentials = null;
|
var credentials = null;
|
||||||
var followRedirects = true;
|
var followRedirects = true;
|
||||||
|
var binaryMode = false;
|
||||||
var headers = {};
|
var headers = {};
|
||||||
var timeout = {
|
var timeout = {
|
||||||
"connect": 0,
|
"connect": 0,
|
||||||
|
@ -160,10 +161,20 @@ helma.Http = function() {
|
||||||
this.setUserAgent = function(agent) {
|
this.setUserAgent = function(agent) {
|
||||||
userAgent = agent;
|
userAgent = agent;
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
this.getUserAgent = function() {
|
this.getUserAgent = function() {
|
||||||
return userAgent;
|
return userAgent;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* switches content text encoding on/off
|
||||||
|
*/
|
||||||
|
this.setBinaryMode = function(mode) {
|
||||||
|
binaryMode = mode;
|
||||||
|
};
|
||||||
|
this.getBinaryMode = function() {
|
||||||
|
return binaryMode;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes a http request
|
* executes a http request
|
||||||
|
@ -204,8 +215,8 @@ helma.Http = function() {
|
||||||
if (content) {
|
if (content) {
|
||||||
conn.setRequestProperty("Content-Length", content.length);
|
conn.setRequestProperty("Content-Length", content.length);
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
var out = new java.io.DataOutputStream(conn.getOutputStream());
|
var out = new java.io.OutputStreamWriter(conn.getOutputStream());
|
||||||
out.writeBytes(new java.lang.String(content));
|
out.write(content);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
@ -236,7 +247,13 @@ helma.Http = function() {
|
||||||
body.write(buf, 0, str);
|
body.write(buf, 0, str);
|
||||||
}
|
}
|
||||||
input.close();
|
input.close();
|
||||||
result.content = result.encoding ? body.toString(result.encoding) : body.toString();
|
if (binaryMode) {
|
||||||
|
result.content = body.toByteArray();
|
||||||
|
} else {
|
||||||
|
result.content = result.encoding ?
|
||||||
|
body.toString(result.encoding) :
|
||||||
|
body.toString();
|
||||||
|
}
|
||||||
result.length = result.content.length;
|
result.length = result.content.length;
|
||||||
}
|
}
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
|
|
Loading…
Add table
Reference in a new issue