douqixia7942 2015-09-08 01:43
浏览 111

需要帮助使用HTTPpost将数据发送到服务器

I'm trying to create user accounts for my applicatin and i'm working on the register process i have the following code in an AsynTask extended class:

        HttpClient client = new DefaultHttpClient(httpRequestParams);

        HttpPost post = new HttpPost(SERVER_ADDRESS + "Register.php");

        ArrayList<NameValuePair> dataToSend = new ArrayList<>();
        dataToSend.add(new BasicNameValuePair("name",user.name));
        dataToSend.add(new BasicNameValuePair("username", user.username));
        dataToSend.add(new BasicNameValuePair("password", user.password));


        try {
            post.setEntity(new UrlEncodedFormEntity(dataToSend));

        }catch (UnsupportedEncodingException e){
            e.printStackTrace();
        }
        try {

            HttpResponse httpResponse = client.execute(post);
            Log.d("ServerRequests", "client is executing");
            Log.d("Http Post Response:",httpResponse.toString());

        }catch (ProtocolException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }

useing the log Tag above in the code i figured out that everything in the code is executed except for the line: HttpResponse httpResponse = client.execute(post); here is my php code:

$name=$_POST["name"];
$username=$_POST["username"];
$password=$_POST["password"];
$statement=mysqli_prepare($con,"INSERT INTO users (name,username,password) VALUES (?,?,?)");
mysqli_stmt_bind_param($statement,"sss",$name,$username,$password);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($con);

so would you please help me identify the problem here?

additional information: i'm using wamp server v2.5 and i'm granting Internet permission to my app

?>

  • 写回答

1条回答 默认 最新

  • doudu2515 2015-09-08 02:48
    关注

    HttpClient is deprecated in maybe SDK v20, and clear is that it is not available in SDK v23, you should use HttpURLConnection, see this link

    How to add parameters to HttpURLConnection using POST

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算