WebDAV的与J2ME
题
是否有使用WebDAV与J2ME(一些库或手动编码)的方法吗?
我试过:点击 - javax.microedition.io.HttpConnection 一>,但“搜索”不支持有方法结果 - javax.microedition.io.SocketConnection 一>使用 Http请求 - 没有什么回报响应结果 也许有毛病我的代码或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();
解决方案 2
朱利安+1你是正确的主机性能,QRSO +1,感谢所有! 因此,结果 - 我发现免费WebDAV服务 MyDisk.se (不允许搜索,所以我用PROPFIND)点击 - 使用 WFetch 以玩弄WebDAV请求结果 - 使用网络监视器比较从WFetch和我的应用程序的请求。结果 :)最后,它的工作! 结果代码:
String response = "";
String query = "<?xml version='1.0' encoding='UTF-8'?>\r\n"
+ "<d:propfind xmlns:d='DAV:'>\r\n"
+ "<d:prop><d:getcontenttype/></d:prop>\r\n"
+ "<d:prop><d:getcontentlength/></d:prop>\r\n"
+ "</d:propfind>\r\n";
String len = String.valueOf(query.length());
SocketConnection hc = (SocketConnection) Connector
.open("socket://79.99.7.153:80");
DataOutputStream dout = new DataOutputStream(hc.openOutputStream());
DataInputStream din = new DataInputStream(hc.openInputStream());
String userPass = "login" + ":" + "password";
byte[] encoded = Base64OutputStream.encode(userPass.getBytes(), 0,
userPass.length(), false, false);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
String request = "PROPFIND /mgontar/ HTTP/1.1\r\n"
+ "Depth: 1\r\n"
+ "Host: mydisk.se:80\r\n"
+ "Accept: */*\r\n"
+ "Content-Type: text/xml\r\n"
+ "Content-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();
其他提示
你是什么意思“没有回报”呢?无响应的身体?无状态码?
我建议跟踪发生了什么事情的“线” ......
更新:?你尝试添加主机标头
FYI如果你是一个实际的手机上测试,然后有一个公平的机会,您的移动网络运营商可能会阻止非HTTP流量。
您可能想先检查,你可以做GET和POST请求到服务器第一。
不隶属于 StackOverflow