J2ME와 Webdav
문제
J2ME (일부 라이브러리 또는 수동 코딩)와 함께 WebDAV를 사용하는 방법이 있습니까?
난 노력 했어:
- 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
Julian +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();
다른 팁
"Nothing Returns"란 무엇을 의미합니까? 응답 기관이 없습니까? 상태 코드가 없습니까?
"와이어"에서 일어나는 일을 추적하는 것이 좋습니다 ...
업데이트 : 호스트 헤더 추가를 시도해 보셨습니까?
참고로 실제 휴대 전화에서 테스트하는 경우 모바일 네트워크 운영자가 HTTP가 아닌 트래픽을 차단할 수있는 기회가 있습니다.
먼저 서버에 요청을 게시하고 게시 할 수 있는지 확인할 수 있습니다.
제휴하지 않습니다 StackOverflow