android httpclient 怎样实现将安卓的一段数据(字符串)上传到服务器 服务器php+apache 怎么接收
发布网友
发布时间:2022-05-19 03:50
我来回答
共2个回答
热心网友
时间:2024-03-04 01:32
手机端的------// 提交反馈信息,这是post方式提交
服务端,php不懂说以,你再找找,跟客户端关系不大
public String user_feedback(String feedbackType,String feedbackContent,String contacts) {
ArrayList<NameValuePair> nv=new ArrayList<NameValuePair>();
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;
}
热心网友
时间:2024-03-04 01:33
get,post
php接受:
$_GET['参数名']
$_POST['参数名']