+ Start a Discussion

How to write HttpRequest and Response for Servlet?

Hi all,


I need help on how to write a http request with servlet.

Here is the situation:

I have to call this url:


From the url, I will get all customer data in JSON Object, which I have to parse later and save it into Customer object in Salesforce.


Since I'm new in backend programming and webservices call, could anyone help me on how to get the response from those url in apex code?

Here is the code that I have until now (sorry, if I'm maybe completely wrong on this):


String url = 'http://x.x.x.x/dev_back/CustomerServlet?action=0&user=john';

Http h = new Http();

// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint 
HttpRequest req = new HttpRequest();

// Send the request, and return a response 
HttpResponse res = h.send(req);

 But with the code above, I'm not be able to get the response. When I take a look on res.getBody() message, I saw that the url is being cut off, it takes only "http://x.x.x.x/dev_back/CustomerServlet?" as the string url.


How can I solve this?



Jia HuJia Hu
There is an example,
Sample: Parsing a JSON String and Deserializing It into Objects