webserver接收不到android发来的json数据
自己搭建了一个webserver,用androidpostjson数据,但没接收到,是为什么HttpClientclient=newDefaultHttpClient()...
自己搭建了一个webserver,用android post json数据, 但没接收到,是为什么
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://10.38.164.81:8080/save.php");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("name", "ze");
StringEntity entity = new StringEntity(jsonObject.toString());
post.setEntity(entity);
int res = client.execute(post).getStatusLine().getStatusCode(); 展开
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://10.38.164.81:8080/save.php");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("name", "ze");
StringEntity entity = new StringEntity(jsonObject.toString());
post.setEntity(entity);
int res = client.execute(post).getStatusLine().getStatusCode(); 展开
1个回答
展开全部
这样试试,服务器端读取para参数的值就绝链是并肆孙jsonObject.toString()这个字符串,解析得到JSONObject,就可以使用get的方式得到name的雹简值了。
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(“para”, jsonObject.toString()));
post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse response = client.execute(post);
int stateCode = response.getStatusLine().getStatusCode();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(“para”, jsonObject.toString()));
post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse response = client.execute(post);
int stateCode = response.getStatusLine().getStatusCode();
追问
我下面加了一个判断
if (res == 200) {
code
}
else {
Log.i("cat", Integer.valueOf(res).toString());
}
为啥res=500?
追答
500是服务器错误了,你看下是不是服务器端报错了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询