我正在尝试通过XAMPP对httpsost表单android进行操作。我在android中获取httpResponse但是当我尝试在浏览器中加载url时没有显示任何内容。它只显示“无”
“我想从android发送值,当我加载网址时,必须在浏览器中显示这些值。”
protected String doInBackground(String...uri) {
// TODO Auto-generated method stub
try{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(uri[0]);
//httpPost.setHeader("Content-Type","application/x-www-form-urlencoded");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(1);
nameValuePair.add(new BasicNameValuePair("id","somevalue"));
Log.d("debug",nameValuePair.get(0).toString());
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(nameValuePair,HTTP.UTF_8);
httpPost.setEntity(ent);
HttpResponse response = httpClient.execute(httpPost);
// response code
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
Log.d("response",line);
}
} catch (Exception e) {
// Code to handle exception
}
}catch (ClientProtocolException e) {
// TODO Auto-generated catch block
System.out.println("clientprotocolexception");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("IOexception");
e.printStackTrace();
}
return null;
}
................................
<?php
if($_POST){
print_r($_POST);
}
else if($_GET){
print_r($_POST);
}
else{
echo 'NONE';
}
?>
答案 0 :(得分:0)
<?php
if(isset($_POST['id'])){
var_dump($_POST);
echo $_POST['id'];//should out put "someValue"
}else{
echo 'id is not set';
}
?>