网络是否开启了? 在手机浏览器里面试试。
用httpclient post 获取数据 是完全可以的,没什么奥秘。
用httpclient post 获取数据 是完全可以的,没什么奥秘。
解决方案 »
- 在framwork中将Acionbar的icon去掉
- android apk安装运行失败,求助可能原因
- 怎么获取android标准的quick search box的内容
- Andriod 是不是Linux的一个版本,是不是Linux内核
- 打算开始Android开发,正在下载API,有个API版本的疑问
- 请教。简单的activity跳转错误。
- JAVA 操作NDK中使用C++类
- Android开发国际化,英文下正常显示,中文显示数字,求解答
- Android: 在一个view1点击text或者button,view2(大小只有view1的一半大或者更小)现实在view下面
- The import com.jauker cannot be resolved
- 在android开发平台上如何实现图像的滤镜效果(类似photo booth 实现的实时镜头特效功能)
- 求助,关于匿名binder的问题
手机浏览器里面用 js也可以
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlStr);
try{
StringEntity sn = new StringEntity(content);
httppost.setEntity(sn);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity(); InputStream instream = entity.getContent();
byte[] buf = new byte[(int) entity.getContentLength()];
instream.read(buf);
return buf;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
不行的,不清楚是不是传的参数不对,
我要传过去的是个json格式的参数
一般是 key=字符串 这个字符串urlEncoder一下
唯独用android 的post的出问题, get也问题.
function post() {
$.post(hostad+'/api/Feedback',
{ "name": "32", "title": "就是测试", "content": "就是测试1" }, //参数
function (data) { $("span").text(data.result);}, "json")
.success(function () { alert("second success"); })
.error(function (e) { alert("error" );
});
}js 是这样的
服务端执行结果
public String httpPost(String baseUrl, List<BasicNameValuePair> params) {
String result = "";
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost postMethod = new HttpPost(baseUrl);
postMethod.setEntity(new UrlEncodedFormEntity(params, "utf-8"));
HttpResponse response = httpClient.execute(postMethod); // 执行POST方法
int code = response.getStatusLine().getStatusCode(); // 获取响应码
if (code == 200) {
result = EntityUtils.toString(response.getEntity(), "utf-8"); // 获取响应内容
} } catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
}
return result;
} public JSONObject httpPostJson(String baseUrl,
List<BasicNameValuePair> params) {
String src = httpPost(baseUrl, params);
JSONObject result = null;
if (!"".equals(src)) {
try {
result = new JSONObject(src);
} catch (JSONException e) {
e.printStackTrace();
}
}
return result;
} public JSONObject httpPostJson(String baseUrl, JSONObject params)
throws ClientProtocolException, IOException, JSONException {
JSONObject result = null;
HttpPost request = new HttpPost(baseUrl);
NavType.LOG("httpPostJson:" + baseUrl + "?" + params.toString());
StringEntity se = new StringEntity(params.toString());
request.setEntity(se);
HttpResponse httpResponse = new DefaultHttpClient().execute(request);
int code = httpResponse.getStatusLine().getStatusCode();
NavType.LOG("httpPostJson:"+code);
if (code == 200) {
String retSrc = EntityUtils.toString(httpResponse.getEntity());
result = new JSONObject(retSrc);
}
return result;
}
安卓的用2种方式都执行不成功
02-26 11:46:53.706: E/---NavType---(26780): httpPostJson:500
02-26 11:46:53.716: E/---NavType---(26780): httpPostJson:{"Message":"发生错误。"}对应输出日志方法
NavType.LOG("httpPostJson:" + baseUrl + "?" + params.toString());
NavType.LOG("httpPostJson:"+code);
NavType.LOG("httpPostJson:"+EntityUtils.toString(httpResponse.getEntity()));问题是服务器也没报错,android这边也没报错,
应该是iis上报的错,我不清楚在哪看iis上的错误.