You need to sign in to do that
Don't have an account?
Azam Khan 1
error while calling GET method with parameters of REST webservice from salesforce
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
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
Sajana Thomas 3
Hi.. Were you able to solve this problem? I am facing the same issue. Please update if you know the fix.