作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我需要一些帮助才能开始。
我需要知道如何调用REST 服务 和解析xml。
我的 php 脚本只发回一些 xmlcode,没有别的。(没有 wsdl 或 uddi)
诺基亚 5800 的平台是S60 第三版。(那个将适用)诺基亚 sdk go 同名。我为这个项目安装了 Netbeans。
我找到的唯一东西是 soap based .
为此我可以使用哪些方法/库?
我不得不提一下,我也是 java/netbeans 的新手。
最佳答案
要调用 REST 网络服务,您可以使用 HttpConnection 类:
HttpConnection connection = null;
InputStream is = null;
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] response = null;
try {
connection = (HttpConnection)Connector.open("http://api.yourserver.com/rest/things/12", Connector.READ);
connection.setRequestMethod(HttpConnection.GET);
connection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
if (connection.getResponseCode() == HttpConnection.HTTP_OK) {
is = connection.openInputStream();
if (is != null) {
int ch = -1;
while ((ch = is.read()) != -1) {
bos.write(ch);
}
response = bos.toByteArray();
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (bos != null) {
bos.close();
bos = null;
}
if (is != null) {
is.close();
is = null;
}
if (connection != null) {
connection.close();
connection = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
现在 response 将包含您的服务器输出的 XML。
关于xml - 使用 JME(或 J2ME)使用 REST 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1202350/
我是一名优秀的程序员,十分优秀!