您可以为服务器发送POST并读取结果.
这是我使用JSON对象的实现,你应该做类似的事情:
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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1948 次 |
| 最近记录: |