• Azam Khan 1
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
i am trying to call a GET method of REST webservice with parameters, but in I am getting the error POST method not supported, don't know why instead of calling GET method it is showing POST method not supported error.

my end point url is http://xxxxxx:8080/sales-core/v1.0/sales/account/details
and I am trying to pass accountNumber=123&contact=testuser&recomendation=true as parameter


callout method is as below
global static String callout(){
            Http http = new Http();
            HttpRequest request = new HttpRequest();        
            String accNo='12596';
            String cont = 'TestUser';
            String recom = 'false';
            request.setEndpoint('http://xxxx:8080/sales-core/v1.0/sales/account/details');
            Map<String,object> mapEmp = new Map<String,object>();
            mapEmp.put('accountNumber',accNo);
            mapEmp.put('contact',cont);
            mapEmp.put('recommendation',recom);
            String JSONString = JSON.serialize(mapEmp);
            request.setCompressed(true);
            request.setBody(JSONString);
            request.setMethod('GET');
            String responseBody = null;
            HttpResponse response = null;
            try {
                response = http.send(request);
            } catch(System.CalloutException e) {
                System.debug('Callout error: '+ e);
                System.debug(response.toString());
            }
            responseBody = response.getBody();
            return responseBody;
}

i have also tried setting request body as 
request.setBody('accountNumber='+EncodingUtil.urlEncode(accNo, 'UTF-8')+'&contact='+EncodingUtil.urlEncode(cont, 'UTF-8')+'&recommendation='+EncodingUtil.urlEncode(recom, 'UTF-8'));

urgent help required