Android HttpPost不发送帖子数据

时间:2014-02-10 16:54:22

标签: php android http post

我在网上发现了很多信息,但无法让我的Android应用程序发送Post数据,它连接到我服务器上的php文件,但我的服务器没有收到$ _POST ['task']。

这是我的应用程序连接代码,其中params是3部分名称值列表:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setEntity(new UrlEncodedFormEntity(params));
httpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

和我的index.php文件的缩减版本:

if(isset($_POST['task']) && $_POST['task'] != ''){

$task = $_POST['task'];
$response = array("task" => $task, "success" => 0, "error"=> 0);

require_once 'include/handler.php';
$db_handler = new Handler();

//log in, check user details.
  if($task == 'login'){
    //do some stuff to check login      
  }else {
      $response["error"] = 1;
      $response["error_msg"] = "Incorrect TASK";
      echo json_encode($response);
  } 

}else{
    $response["error"] = 1;
    $response["error_msg"] = "TASK NOT PRESENT";
    echo json_encode($response);
}

它只会回复最终,而不是任何其他信息。任何帮助将不胜感激,我在研究中使用的教程就在这里:

http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

0 个答案:

没有答案