You need to sign in to do that
Don't have an account?
sony sonu
rest callouts
public class Callouts {
public static pageReference makeGetCallout() {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
// Deserializes the JSON string into collections of primitive data types.
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
List<Object> values = (List<Object>) results.get('values');
System.debug('Received the following values:');
for (Object value: values) {
System.debug(value);
}
}
return null;
}
public static pageReference makePostCallout() {
String S ='{"Deduction": [{"Cxatxegoxry_Tyxpe": "xV","xxx": 125.00}],"isOxxnlinexxxxxr": true}';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(' http://xxxxxxxxxxxxxxxxxxxxxxxxxx');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setHeader('ip', '2xxxxxxxxxx');
request.setBody('S');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
return null;
}
}
v.f page is :
<apex:page controller="Callouts" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:commandButton value="GET" action="{!makeGetCallout}"/>
<apex:commandButton value="POST" action="{!makePostCallout}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
iam not getting the response on clicking the button may i know where is the mistake?
public static pageReference makeGetCallout() {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
// Deserializes the JSON string into collections of primitive data types.
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
List<Object> values = (List<Object>) results.get('values');
System.debug('Received the following values:');
for (Object value: values) {
System.debug(value);
}
}
return null;
}
public static pageReference makePostCallout() {
String S ='{"Deduction": [{"Cxatxegoxry_Tyxpe": "xV","xxx": 125.00}],"isOxxnlinexxxxxr": true}';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(' http://xxxxxxxxxxxxxxxxxxxxxxxxxx');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setHeader('ip', '2xxxxxxxxxx');
request.setBody('S');
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
return null;
}
}
v.f page is :
<apex:page controller="Callouts" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:commandButton value="GET" action="{!makeGetCallout}"/>
<apex:commandButton value="POST" action="{!makePostCallout}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
iam not getting the response on clicking the button may i know where is the mistake?
All Answers
after keeping that also it is not executing,, i think , pagereference declaration is worng ...please provide the solution you know