在与Android的凌空库将数据发送到服务器 [英] Send data to server with Volley Lib in Android

查看:134
本文介绍了在与Android的凌空库将数据发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的Json 开发了我要去从手机到服务器发送数据的应用,要做到这一点我使用 排球 库中的Andr​​oid。结果
但我不能发送数据到服务器!

I've developed a Application that i'm going to send data from the phone to the server by Json, to do this i use Volley Library in Android.
but i can not send data to the server!

我简单的PHP code:

my simple php code :

$name = $_GET["name"];
$j = array('name' =>$name);
echo json_encode($j);

我的Java code:

my java code :

private void makeJsonObjectRequest() {
        mRequestQueue = Volley.newRequestQueue(this);
        String url = "http://my-site-name/sampleGET.php";

        StringRequest jsonObjReq = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.d("result:", response);
                        Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("err", "Error: " + error.getMessage());
                makeJsonObjectRequest();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<>();
                params.put("name", "json");
                return params;
            }
        };
        mRequestQueue.add(jsonObjReq);
    }

这也得到了以下链接帮助:<一href=\"http://stackoverflow.com/questions/25948191/send-post-request-using-volley-and-receive-in-php\">Click看到链接

但仍然不能使用它,并从移动数据发送到服务器!结果
我怎样才能做到这一点?
请给我正确的,如何使用它

But still could not use it and send data from mobile to server!!!
How can I do this? Please give me correct and how to use it

推荐答案

我做这个而依据后,我希望它可以提供帮助。
你不会我上传图片,但你将派出一个例子,你可以在这条线看到:

I did a gist on this a while back I hope it can help. You won't me uploading images, however you will be sending an example of which you can see on this line:

entityBuilder.addTextBody("someparameter", params.toString());

在精神我使用Apache的HttpClient 4乱射。链接到这里要点

In the gist I use apache httpclient 4 with Volley. Link to the gist here.

这篇关于在与Android的凌空库将数据发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆