[英]Http post from android to PHP
I am trying to do httppost form android to php through XAMPP. 我正在尝试通过XAMPP将httppost形式的android转换为php。 I am getting the httpResponse in android but there is nothing displayed when i try to load the url in browser.
我在android中获得了httpResponse,但是当我尝试在浏览器中加载url时没有显示任何内容。 It only displays "NONE"
它只显示“ NONE”
"I want to send the value from android and those must be displayed in the browser when i load the 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';
}
?>
<?php
if(isset($_POST['id'])){
var_dump($_POST);
echo $_POST['id'];//should out put "someValue"
}else{
echo 'id is not set';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.