其余调用Web服务? [英] calling rest web service?
本文介绍了其余调用Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的Android的发展。我想打电话给一个休息的Web服务,并显示一个简单的txt文件或和XLS文件。
那可能吗?如果是,怎么了?预先感谢您...
i'm new to android development. i want to call a rest web service and show a simple txt-file or and xls-file. is that possible? and if it is, how? thank you in advance...
推荐答案
您可以发送的服务器发布和阅读的结果。
You can send a POST for the server and read the result.
这是我的一个JSON对象实现,你应该做类似的东西:
This is my implementation with a JSON object, you should do something like it:
JSONObject obj = new JSONObject();
obj.put("jsonrpc", "2.0");
obj.put("method", "getSomething");
JSONObject auth = new JSONObject();
auth.put("email", "user");
auth.put("password", "pass");
params.put("auth", auth);
obj.put("params", params);
int TIMEOUT_MILLISEC = 10000; // = 10 seconds
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost request = new HttpPost("server address");
try {
StringEntity entity = new StringEntity(obj.toString());
entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
request.setEntity(entity);
ResponseHandler<String> handler = new BasicResponseHandler();
String returnValue = client.execute(request, handler);
//returnValue has the return from the server.
} catch (Throwable e) {
e.printStackTrace();
}
这篇关于其余调用Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文