如何发送的Htt prequest并获得Android的JSON响应? [英] how to send HttpRequest and get Json response in android?

查看:189
本文介绍了如何发送的Htt prequest并获得Android的JSON响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个Android应用程序使用 WP-API插件我的话preSS网站。我如何发送的Htt prequest(GET),并在recive JSON响应?

i want to build an android app for my wordpress website using wp-api plugin. how can i send HttpRequest(GET) and recive response in Json?

推荐答案

尝试下面code从URL获取JSON

Try below code to get json from a URL

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget= new HttpGet(URL);

HttpResponse response = httpclient.execute(httpget);

if(response.getStatusLine().getStatusCode()==200){
   String server_response = EntityUtils.toString(response.getEntity());
   Log.i("Server response", server_response );
} else {
   Log.i("Server response", "Failed to get server response" );
}

这篇关于如何发送的Htt prequest并获得Android的JSON响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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