简体   繁体   English

HTTP请求库从Apache服务器获取JSON

[英]http-request library get JSON from Apache server

I used kevinsawicki/http-request library to send data to Apache server. 我使用kevinsawicki/http-request 将数据发送到Apache服务器。 From this link , we can send data to server like my code bellow : 通过此链接 ,我们可以像下面的代码一样将数据发送到服务器:

new Thread(
        new Runnable(){
            public void run(){
                Map<String, String> data = new HashMap<String, String>();
                data.put("data", "A User");

                if (HttpRequest.post(MainActivity.private_ip).form(data).created())
                  Log.i("xxx", "Data sent");
            }
}).start();

Web services (*.php) 网络服务(* .php)

<?php
    if(isset($_POST["data"]) && $_POST["data"] != '' ){     
        $data = $_POST["data"];

        // some action here

        // response to android client application
        $response[TAG_SUCCESS] = 0;     
        $response[TAG_ERROR_CODE] = 5;
        $response[TAG_MESSAGE] = "Access Denied";
        echo json_encode($response);
    }
?>

So, I need to read response in JSON form from server, and unfortunately i don't know. 因此,我需要从服务器读取JSON形式的响应,但是不幸的是我不知道。 how i do that? 我该怎么做? What i missed? 我错过了什么? if I am misunderstanding about the use of this library? 如果我对使用该库有误解?

Many thanks. 非常感谢。

If you're already using apache, you might want to look into Apache HttpComponents . 如果您已经在使用apache,则可能需要研究Apache HttpComponents It makes sending GET, POST, PUT and other HTTP requests very simple. 它使发送GET,POST,PUT和其他HTTP请求变得非常简单。 Here is an example of a GET request sent using this library. 这是使用此库发送的GET请求的示例。 You should be able to get the information you need from this, and manipulate it to fit your needs. 您应该能够从中获得所需的信息,并对其进行操作以适应您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM