あなたは、HTTP GETリクエストを使用して、サーバーからのInputStreamとしてXMLを要求し、リクエストパラメータとしてパラメータを渡すだけでできますからストリームを取得することができます以下のような方法が何かを
http://some.server/webapp?period=1&userid=user1
をサーバー:
/**
* Returns an InputStream to read from the given HTTP url.
* @param url
* @return InputStream
* @throws IOException
*/
public InputStream get(final String url) throws IOException {
HttpClient httpClient = new DefaultHttpClient();
HttpParams httpParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT);
HttpGet httpget = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpget);
StatusLine statusLine = httpResponse.getStatusLine();
if(! statusLine.getReasonPhrase().equals("OK")) {
throw new IOException(String.format("Request failed with %s", statusLine));
}
HttpEntity entity = httpResponse.getEntity();
return entity.getContent();
}
そしてあなたはJAXBのようなエンティティにXMLを解析するために、 "シンプル"(http://simple.sourceforge.net/)XMLライブラリを使用することができます。
/**
* Reads the XML from the given InputStream using "Simple" and returns a list of assignments.
* @param InputStream
* @return List<Assignment>
*/
public List<Assignment> readSimple(final InputStream inputStream) throws Exception {
Serializer serializer = new Persister();
return serializer.read(AssignmentList.class, inputStream).getAssignments();
}
私は、RESTサービスを使っているだけなので、リクエストパラメータは使用しません。
うんは、私にはいいですね:) 1 – tutts
HTTPのPOSTが優れているサポートされている場合、バック+1 :-) –
パラメータが一致した場合、それはサーバー上で、それぞれの関数を呼び出すん......?私が言ったように、私はサーバー上でfetchAssignment(int、string)を呼び出す必要があります... – Kishan