How to send request and get response from server when working with Rest API.

 Http http1=new Http();
 HttpRequest req1=new HttpRequest();
 req1.setmethod('POST'); //you can also SET method `GET` with Get there is no need of req1.setbody()
 HttpResponse res1;
 res1 = http1.send(req1);
 String str=res1.getbody();
| improve this answer | |

The details of making HTTP callouts in Apex are found in the developer.force.com wiki pages here:


| improve this answer | |
  • 1
    Hi Aisha. Welcome to SFSE. As you appear to be new I'd like to invite you to read a little about etiquette and use of stack exchange. The expectations for interaction are a bit more structured than a discussion forum. So when you get a chance, take a look here: salesforce.stackexchange.com/tour . – pchittum Dec 13 '13 at 12:42

These Is How You Can Send A request or get Response

public class pincode {

public string x {get;set;}
    public PageReference click() {

   http p = new http();// invoiking Http Class
httprequest req= new httprequest(); //Invoking RestRequest
req.setEndpoint('http://pin-codes.in/api/pincode/500072');//Setting Endpoint
req.setMethod('GET');// Setting Method 
httpresponse res = new httpresponse();
x= res.getbody();// Catching Response 
        return null;

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.