Skip to main content

RESTFul Client on Android

I was surfing on net , i didn't get a needed help on RESTful Client on Android, so I decided to write my own.
Following is the code..

First of all REST service architecture uses all the basic operations of HTTP to interact.

First of all u would have to set make a HttpGet method with the URI to be requested.

HttpGet httpGet=new HttpGet(new URI("www://abc.con");

i have used new URI() as a get parameter because if u are sending some parameters with the GET request , it will encode the parameters ready to be sent along the network channel.

Second step is that u will have to make a HttpClient which will execute the GET request that we have made.
It is made as follows--
HttpClient httpClient=new DefaultHttpClient();

now execute the GET request from the HttpClient
as
Make a variable to hold Response of the request
HttpResponse httpResponse=httpClient.execute(httpGET);

to convert the Response to string use the following line
String result=EntityUtils.toString(httpResponse.getEntity());


So ur result is ready as a string, u can use various parser according to response types ie XML and JSON.


In the next post i will explain the basics of Rest Client by using Spring Android Framework , which is better and easy to use, u do not have to consider any response types ,it automatically parses all data for u,
So wait for next article.

Comments

  1. I forgot to mention in this post that , all netwotrk related operations , ie
    client.execute() where response is feteched,infact u should run all the above code using AsyncTask or using Thread, because ANdorid does not allow network related operations to be running on main UI thread , it will throw out NetworkOnMainUIThreadException .

    ReplyDelete

Post a Comment

Popular posts from this blog

Database Sharding

Collating some of the resources which talks about Database Sharding. https://en.wikipedia.org/wiki/Shard_(database_architecture) [Feb 2019]  http://highscalability.com/blog/2019/2/19/intro-to-redis-cluster-sharding-advantages-limitations-deplo.html Redis Cluster is the Native Sharding implementation available within Redis that allows your to automatically distribute your data across multiple nodes without having to rely on external tools and utilities. Its covers Sharding with Redis Cluster  where Redis Clusters is divided in 16384 slots and these slots are assigned to multiple Redis Nodes. The  Redis Cluster Specification  is the definitive guide to understanding the internals of the technology, while the  Redis Cluster Tutorial  provides deployment and administration guidelines. [ Jan 2019  ]  https://scalegrid.io/blog/scalegrid-hosting-adds-support-for-highly-available-redis-clusters-with-automated-sharding/ ScaleGrid : Fully Manage...

Penetration Testing Basics

Penetration testing, often called “pentesting”,“pen testing”, or “security testing”, is the practice of attacking your own or your clients’ IT systems in the same way a hacker would to identify security holes. Of course, you do this without actually harming the network. The person carrying out a penetration test is called a penetration tester or pentester. The difference between Penetration Testing and Hacking is that you have the system owner's permission to do testing and to identfiy security holes. If you want to do penetration testing u should better ask for his/her permission. Basic Security Concepts Vulnerability: It is a security hole in a piece of software, hardware of Operating system that provides a way to attack the system.A vulnerabilty is as simple as weak passwords and as complex as buffer overflows as well as SQL injection. Security Research: Vulnerabilities are typically searched by security researchers who finds the flaws in the system. Security Research can ...