android httpclient 怎样实现将安卓的一段数据(字符串)上传到服务器 服务器php+apache 怎么接收

求代码 安卓的和php的 求各位大神帮忙啊 就剩50分了
2024-11-29 00:59:33
推荐回答(2个)
回答1:

手机端的------// 提交反馈信息,这是post方式提交
服务端,php不懂说以,你再找找,跟客户端关系不大

public String user_feedback(String feedbackType,String feedbackContent,String contacts) {
ArrayList nv=new ArrayList();
nv.add(new BasicNameValuePair("userId", this.user.userid));
nv.add(new BasicNameValuePair("feedbackType", feedbackType));
nv.add(new BasicNameValuePair("feedbackContent",feedbackContent));
nv.add(new BasicNameValuePair("userContact",contacts));
nv.add(new BasicNameValuePair("permit", this.user.permit));
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(uri);
String strResult = "";
try {
HttpEntity entity = new UrlEncodedFormEntity(nv, "UTF-8");
post.setEntity(entity);
// 获得HttpResponse对象
HttpResponse httpResponse = client.execute(post);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// 取得返回的数据
strResult = EntityUtils.toString(httpResponse.getEntity());
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Log.i("jsonHelper", strResult);
return strResult;
}

回答2:

get,post
php接受:
$_GET['参数名']
$_POST['参数名']