本文介绍了如何发送与排球的数据POST请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Andr​​oid code

 的JSONObject PARAMS =新的JSONObject();
           params.put(用户名,[email protected]);
           params.put(密码,hellothere);

           JsonObjectRequest loginRequest =新JsonObjectRequest(
                    Request.Method.POST,
                    http://192.168.2.67/tmp/test.php
                    参数,可以
                    新Response.Listener<的JSONObject>(){
                        @覆盖
                        公共无效onResponse(的JSONObject的JSONObject){
                        Log.d(,);

                        }
                    },
                    新Response.ErrorListener(){
                        @覆盖
                        公共无效onErrorResponse(VolleyError volleyError){
                        Log.d(,);
                        }
                    });


            requestQueue.add(loginRequest);
 

服务器code在PHP

 < PHP
               $ USR = $ _REQUEST [用户名];
                $ PWD = $ _REQUEST ['密码'];
                $ RESP [$ USR] = $ PWD;
                回声json_en code($ RESP);
               ?>
 

我得到的回应是{:空}

我试着用的Apache HTTP cleint和它的工作prferectly有什么办法我可以凌空做到这一点?

解决方案

来源:异步HTTP请求的Andr​​oid使用凌空

This is my android code

           JSONObject params = new JSONObject();
           params.put("username","[email protected]");
           params.put("password","hellothere");

           JsonObjectRequest loginRequest = new JsonObjectRequest(
                    Request.Method.POST,
                    "http://192.168.2.67/tmp/test.php",
                    params,
                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject jsonObject) {
                        Log.d("","");

                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError volleyError) {
                        Log.d("","");
                        }
                    });


            requestQueue.add(loginRequest);

The server code in php

            <?php
               $usr = $_REQUEST['username'];
                $pwd = $_REQUEST['password'];
                $resp[$usr]=$pwd;
                echo json_encode($resp);
               ?>

the response i'm getting is{"":null}

I tried with apache http cleint and it worked prferectlyis there any way i can do this with volley?

解决方案

Source: Asynchronous HTTP Requests in Android Using Volley

这篇关于如何发送与排球的数据POST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:47