有没有办法将 WebDAV 与 J2ME(一些库或手动编码)一起使用?
我尝试过:
- javax.microedition.io.HttpConnection,但那里不支持“SEARCH”方法
-带有Http 请求的javax.microedition.io.SocketConnection - 没有任何返回响应
可能我的代码或 HTTP 标头有问题:
String response = "";
String query = "<?xml version='1.0'?> "
+ "<g:searchrequest xmlns:g='DAV:'> "
+ "<g:sql> "
+ "SELECT 'DAV:displayname' "
+ "FROM 'http://exchangeserver.com/Public/' "
+ "</g:sql> "
+ "</g:searchrequest> ";
String len = String.valueOf(query.length());
SocketConnection hc = (SocketConnection) Connector
.open("socket://exchangeserver.com:8080");
DataOutputStream dout =
new DataOutputStream(hc.openOutputStream());
DataInputStream din = new DataInputStream(hc.openInputStream());
String userPass = "username" + ":" + "password";
byte[] encoded =
Base64OutputStream.encode(userPass.getBytes(), 0,
userPass.length(), false, false);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
String request = "SEARCH /Public/ HTTP/1.1\r\n"
+"Content-Type:text/xml\r\nContent-Length:"
+ len
+ "\r\nAuthorization:Basic "
+ new String(encoded)
+ "\r\n\r\n";
bos.write(request.getBytes());
bos.write(query.getBytes());
dout.write(bos.toByteArray());
dout.flush();
dout.close();
byte[] bs = new byte[900];
din.readFully(bs);
bos = new ByteArrayOutputStream();
bos.write(bs);
din.close();
hc.close();
response = bos.toString();