我得到了:
已消耗IllegalStateException内容
这是我的代码
private String postRequest(String strRequestURL,HashMap<String, Object> dataParams,HashMap<String, Object> headerParams){
String strResponse = "no resp";
HttpPost httpPost;
HttpClient httpClient;
HttpParams httpParams;
try {
httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 10*60*1000);//10 min
HttpConnectionParams.setSoTimeout(httpParams, 10*60*1000);//10 min
httpClient = new DefaultHttpClient(httpParams);
httpPost = new HttpPost(strRequestURL);//new HttpPost(requestURL);
Iterator iterHeader =headerParams.entrySet().iterator(); //postHeaderParams.entrySet().iterator();
while (iterHeader.hasNext()) {
Map.Entry mEntry = (Map.Entry) iterHeader.next();
httpPost.setHeader(mEntry.getKey().toString(), mEntry.getValue().toString());
}
Iterator iter =dataParams.entrySet().iterator();
JSONObject objParams = new JSONObject();
while (iter.hasNext()) {
Map.Entry mEntry = (Map.Entry) iter.next();
//params.add(new BasicNameValuePair(mEntry.getKey().toString(), mEntry.getValue().toString()));
objParams.put(mEntry.getKey().toString(),mEntry.getValue().toString());
}
httpPost.setEntity(new StringEntity(objParams.toString(), "UTF-8"));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if(statusCode==200)
{
Log.i("log", "connection code status true");
}
strResponse = EntityUtils.toString(entity,HTTP.UTF_8);
}
catch (Exception ex) {
ex.printStackTrace();
Common.logError(context , ex.getMessage(), "API call - " + strRequestURL, "postRequest");
}
return strResponse;
}
我无法找到消费内容的确切问题。
我已经按照这些链接但没有运气:
IllegalStateException: Content has been consumed
IllegalStateException: Content has been consumed using httpPost to get data from server
Android HttpResponse - Content has been consumed
"IllegalStateException: Content has been consumed"
IllegalStateException: Content has been consumed - How to resolve?