You need to sign in to do that
Don't have an account?
sony sonu
getting response in anonymous window and not getting response in vf page
public class OrgRestDemoController2 {
public static void submit() {
HttpRequest request = new HttpRequest();
request.setEndpoint('http://.sfdkcimmmn.com/api/responsexxx');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
string Str ='{"Name": "ddu","Type": "xxx", "PayFrequency": "0R1jIbo/lZquTYoMRtljVw=="}';
request.setBody(str);
//request.setCompressed(true);
Http http = new Http();
HTTPResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 200) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
}
else
{
System.debug(response.getBody());
}
}
}
===============================================================
<apex:page controller="OrgRestDemoController2" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!submit}" value="submit" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
on clicking on submit button, iam not getting the blank page,,,,, bt in anonymous window it got executed,, may in know my method is correct or wrng please...or i should use page reference method instead of the submit??? can please rewrite the code ..to executeit thanks in advance...
public static void submit() {
HttpRequest request = new HttpRequest();
request.setEndpoint('http://.sfdkcimmmn.com/api/responsexxx');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
string Str ='{"Name": "ddu","Type": "xxx", "PayFrequency": "0R1jIbo/lZquTYoMRtljVw=="}';
request.setBody(str);
//request.setCompressed(true);
Http http = new Http();
HTTPResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 200) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
}
else
{
System.debug(response.getBody());
}
}
}
===============================================================
<apex:page controller="OrgRestDemoController2" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!submit}" value="submit" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
on clicking on submit button, iam not getting the blank page,,,,, bt in anonymous window it got executed,, may in know my method is correct or wrng please...or i should use page reference method instead of the submit??? can please rewrite the code ..to executeit thanks in advance...
Please mark best answer from the above answers if your problem get solved
Thank you.
All Answers
vf
First add remote site setting for this url and most important thing your Endpoint url is in wrong format there is one dot extra in it so please have a look correct formatted url is this http://sfdkcimmmn.com/api/responsexxx paste this url in remote site setting.
If still your problem is not solved then let me know and please also upload image of what u r getting after calling acion.
Thanks
Saket Sharma
GhanshyamChoudhari, thanks for your reply, iam getting the error,please let me know if you have any idea
thanks for your help...
i had done the remote site setting and it is correct url... i got response in anonymous window,,,, actually i had not shared the corect url due to privacy..
Thanks for information u shared ,
as your submit method is static so for this you to make responsejson variable is to be static or second approach can be to remove static keyword from the submit method.
and if you want to refrence this responseJson in VF page then make it public also.
Hope it wil work, if your problem get solved then please mark my answer as a best answer.
Thanks
Use this vf code Snippet and I think it will work, If your problem get solved then please mark it as a best answer.
Thanks
Saket Sharma
hi Saket &
GhanshyamChoudhari , thanks for your support, iam sorry, to say that iam getting the above error please
Please mark best answer from the above answers if your problem get solved
Thank you.