使用J2ME的WebDAV

编程入门 行业动态 更新时间:2024-10-27 13:35:26
本文介绍了使用J2ME的WebDAV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法将WebDAV与J2ME(某些库或手动编码)一起使用?

Is there a way to use WebDAV with J2ME (some libraries or manual coding)?

我试过: - javax.microedition.io.HttpConnection ,但不支持SEARCH方法 - javax.microedition.io.SocketConnection 与 Http请求 - 没有任何回复 我的代码或HTTP标头可能有问题:

I've tried: - javax.microedition.io.HttpConnection, but "SEARCH" method not supported there - javax.microedition.io.SocketConnection with Http request - nothing returns in response Maybe something wrong with my code or HTTP header:

String response = ""; String query = "<?xml version='1.0'?> " + "<g:searchrequest xmlns:g='DAV:'> " + "<g:sql> " + "SELECT 'DAV:displayname' " + "FROM 'exchangeserver/Public/' " + "</g:sql> " + "</g:searchrequest> "; String len = String.valueOf(query.length()); SocketConnection hc = (SocketConnection) Connector .open("socket://exchangeserver: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();

推荐答案

Julian +1你是对主机房产,QRSO +1,感谢大家! 所以, - 我找到了免费的WebDAV服务 MyDisk.se (不允许搜索,所以我使用PROPFIND) - 使用 WFetch 使用WebDAV请求 - 使用网络监视器,用于比较WFetch和我的应用程序的请求。 :)最后它正在工作! 结果代码:

Julian +1 you was right for Host property, QRSO +1, thanks to all! So, - I have found free WebDAV service MyDisk.se (SEARCH not allowed, so I used PROPFIND) - used WFetch to play around with WebDAV request - used Network Monitor to compare requests from WFetch and my app. :) Finally it's working! Result code:

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();

更多推荐

使用J2ME的WebDAV

本文发布于:2023-11-27 23:50:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:J2ME   WebDAV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!