WebDAV with J2ME

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

I tried:
- javax.microedition.io.HttpConnection , but the "SEARCH" method is not supported there
- javax.microedition.io.SocketConnection with Http request - nothing is returned in response
Maybe something is 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 '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(); 
+1
source share
3 answers

Julian +1 you were right for Host property, QRSO +1, thanks everyone! So,
- I found the free WebDAV service MyDisk.se (SEARCH is not allowed, so I used PROPFIND)
- Used by WFetch to play using a WebDAV request
- Network Monitor is used to compare requests from WFetch and my application.
:) Finally it works! 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(); 
+2
source

What does it mean "returns nothing"? No response body? No status code?

I recommend tracking what happens on the wire ...

UPDATE: did you try to add a host header?

+4
source

FYI If you are testing on a real mobile phone, there is a possibility that your mobile network operator may block non-HTTP traffic.

You can first verify that you can first execute GET and POST requests to the server.

+1
source