有没有办法将 WebDAV 与 J2ME 一起使用(一些库或手动编码)?
我试过:
- javax.microedition.io.HttpConnection , 但那里不支持“SEARCH”方法
- javax.microedition.io.SocketConnection与 Http request - 没有任何回应
也许我的代码或 HTTP header 有问题:
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();
最佳答案
“没有返回”是什么意思?没有响应体?没有状态码?
我建议跟踪“电线”上发生的事情...
更新:您是否尝试过添加主机 header ?
关于http - WebDAV 与 J2ME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/716686/