JSONでsessionIDを取得するのに問題があります。JSONは常に新しいsessionIDを返します。応答を要求するためにsessionIDを追加しようとすると、間違ったSessionIDが返されます。開いている場合、または新しいsessionIDを開いている場合は、開いているsessionIDを返し、開いている間は常に同じsessionIDを返す必要があります。
それは私のリクエストクラスです:
public abstract class RequestSender<T> {
private final String requestUrl;
DefaultHttpClient httpclient;
InputStream inputStream;
public RequestSender(String methodName) {
this.requestUrl = Settings.URL + methodName;
}
public void execute() throws IllegalStateException, IOException {
httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(requestUrl);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
}
private String convertResponseToString() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream, "UTF8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
inputStream.close();
return sb.toString();
}
protected JSONObject parseToJSON() throws JSONException, IOException {
return new JSONObject(convertResponseToString());
}
public String getRequestUrl() {
return requestUrl;
}
public abstract T getResults() throws JSONException, IOException;
}
誰かが私を助けることができれば私は感謝します:)。