网络是否开启了? 在手机浏览器里面试试。
用httpclient post 获取数据 是完全可以的,没什么奥秘。
用httpclient post 获取数据 是完全可以的,没什么奥秘。
解决方案 »
- Android中,Button移动位置,其接收事件焦点却没变,求助。
- ListView长按和短按事件的问题
- 急!!!怎么对spinner下拉列表中的item进行各种操作???
- 熟悉PendingIntent 的看下
- 关于Android开机动画
- android手机信号的问题
- 求解如何实现360手机助手那种通过USB接口读取手机信息的问题
- Android怎么实现图片的点击功能,需求描述如下:(急求大神帮忙)
- android关于html5
- 使用ViewPager 加载两个窗体,如果重新加载
- 在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上的错误.