设置超时时间,报堆栈不支持设置参数,该如何解决
设置超时时间,报堆栈不支持设置参数
HttpPost httpRequest = new HttpPost(SERVER_URL); // 根据内容来源地址创建一个Http请求
// HttpEntity entity = new UrlEncodedFormEntity(params);
// httpRequest.setEntity(entity);
// HttpClient client = new DefaultHttpClient();
httpRequest.addHeader("Content-Type", "application/json; charset=utf-8");//必须要添加该Http头才能调用WebMethod时返回JSON数据
JSONObject jsonParams=new JSONObject();
jsonParams.put("name", name);
jsonParams.put("password", password);
jsonParams.put("imei", imei);
jsonParams.put("fahuo_date", fahuo_date);
jsonParams.put("stype", stype);
HttpEntity entity =new StringEntity(jsonParams.toString(), "utf8");//参数必须也得是JSON数据格式的字符串才能传递到服务器端,否则会出现"{'Message':'strUserName是无效的JSON基元'}"的错误
httpRequest.setEntity(entity);
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); // 发送请求并获取反馈
// 请求超时
httpResponse.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000); 到这步就报错了 说 andorid Setting parameters in a stack is not supported
// 读取超时
httpResponse.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 20000);
------解决思路----------------------
顺序错了吧,我记得超时时间应该是在执行 execute 之前在 HttpClient 里设置的
------解决思路----------------------
你都執行了還設置什麼超時時間。
HttpPost httpRequest = new HttpPost(SERVER_URL); // 根据内容来源地址创建一个Http请求
// HttpEntity entity = new UrlEncodedFormEntity(params);
// httpRequest.setEntity(entity);
// HttpClient client = new DefaultHttpClient();
httpRequest.addHeader("Content-Type", "application/json; charset=utf-8");//必须要添加该Http头才能调用WebMethod时返回JSON数据
JSONObject jsonParams=new JSONObject();
jsonParams.put("name", name);
jsonParams.put("password", password);
jsonParams.put("imei", imei);
jsonParams.put("fahuo_date", fahuo_date);
jsonParams.put("stype", stype);
HttpEntity entity =new StringEntity(jsonParams.toString(), "utf8");//参数必须也得是JSON数据格式的字符串才能传递到服务器端,否则会出现"{'Message':'strUserName是无效的JSON基元'}"的错误
httpRequest.setEntity(entity);
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); // 发送请求并获取反馈
// 请求超时
httpResponse.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000); 到这步就报错了 说 andorid Setting parameters in a stack is not supported
// 读取超时
httpResponse.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 20000);
------解决思路----------------------
顺序错了吧,我记得超时时间应该是在执行 execute 之前在 HttpClient 里设置的
------解决思路----------------------
你都執行了還設置什麼超時時間。