java上的XMLHttpRequest
我需要将下面的Javascript伪类转换为Java代码。我在谷歌上搜索有关Java中的XMLHttpRequest(或等效程序)的信息,我感到困惑:java上的XMLHttpRequest,java,xmlhttprequest,Java,Xmlhttprequest,我需要将下面的Javascript伪类转换为Java代码。我在谷歌上搜索有关Java中的XMLHttpRequest(或等效程序)的信息,我感到困惑: function conexionSOAP(url, uri) { // Constructor this.uri = 'urn:' + uri; this.url = url; this.cabeceraXML = '<?xml version="1.0" encoding="UTF-8"?>' + '<soa
function conexionSOAP(url, uri) {
// Constructor
this.uri = 'urn:' + uri;
this.url = url;
this.cabeceraXML = '<?xml version="1.0" encoding="UTF-8"?>'
+ '<soap:Envelope '
+ 'soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" '
+ 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '
+ 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" '
+ 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
+ '<soap:Body>' + '<';
this.sessionKey = null;
// Metodos
var self = this;
(...)
this.llamar_metodo = function(metodo, argumentos, http, loadCallback,
errorCallback) {
// Función que transforma las llamadas a métodos en requests XML
var XMLmsg = self.cabeceraXML + metodo + ' xmlns="' + self.uri + '"';
if (argumentos == null) {
XMLmsg = XMLmsg + ' xsi:nil="true" />';
} else {
var i, I;
XMLmsg = XMLmsg + '>';
for (i = 0, I = argumentos.length; i < I; i++) {
var tipo = typeof argumentos[i];
if (tipo == "number") {
if (argumentos[i] % 1) {
tipo = "float";
} else {
tipo = "int";
}
}
XMLmsg = XMLmsg + '<c-gensym' + (2 * (i + 2))
+ ' xsi:type="xsd:' + tipo + '">' + argumentos[i]
+ '</c-gensym' + (2 * (i + 2)) + '>';
}
XMLmsg = XMLmsg + '</' + metodo + '>';
}
XMLmsg = XMLmsg + '</soap:Body>' + '</soap:Envelope>';
// Una vez preparado el XML preparamos el HttpRequest
http.open("POST", self.url, true);
http.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
http.setRequestHeader('Origin', 'ParkingClientJS');
http
.setRequestHeader('SOAPAction', '"' + self.uri + '#' + metodo
+ '"');
http.timeout = 15000;
http.onload = loadCallback;
http.onerror = errorCallback;
http.ontimeout = errorCallback;
http.send(XMLmsg);
};
function readyState(metodo, http) {
var respuesta = null;
if (http.readyState == 4) {
if (http.status == 200) {
var responseTag = http.responseXML.getElementsByTagName(metodo
+ 'Response');
if (responseTag) {
if (responseTag[0].childNodes.length <= 1) {
respuesta = responseTag[0].childNodes[0].textContent;
} else {
var i, I;
respuesta = [];
for (i = 0, I = responseTag[0].childNodes.length; i < I; i++) {
respuesta
.push(responseTag[0].childNodes[i].textContent);
}
}
}
} else {
respuesta = "--EE--";
}
}
return respuesta;
}
function error_timeOut(http) {
var respuesta = "--EE--";
http.abort();
return respuesta;
}
}
最后,实现必须与android兼容
谢谢你的帮助,我真的对Http的东西感到困惑
对不起,我的英语不好
function(method, [param1, param2, ...], responseCallback){
var http = new XMLHttpRequest();
self.llamar_metodo(method, [ param1, param2, ... ], http, function() {
var response = readyState(metodo, http);
responseCallback(response)
}, function() {
var respuesta = error_timeOut(http);
responseCallback(response)
});
}