I am facing following issue: On load of visualforce page I am making http callout to internal salesforce page but here I facing authentication problem.
If I am running same http callout from developer console then I am getting successful response but that same code is not working with visualforce page. Reason for not working is my session id in developer console and visualforce domain is different.
For fetching session id I am using "UserInfo.getSessionId()"
I have also tried {!$Api.Session_ID} but not working
My controller:
public with sharing class HttpRequestForPage
{
public HttpRequestForPage()
{
requestForPage('https://ap1.salesforce.com/home/home.jsp');
}
public void requestForPage(String pageUrl)
{
HttpResponse responseOfPage;
String responseString;
HttpRequest request = new HttpRequest();
request.setMethod('GET');
request.setEndpoint('https://ap1.salesforce.com/home/home.jsp');
request.setHeader('Cookie', 'sid='+UserInfo.getSessionId());
try
{
responseOfPage = new Http().send(request);
}
catch(Exception e)
{
system.debug(e);
}
responseString = responseOfPage.getBody();
System.debug(responseString=='+responseString);
}
}