salesforce - Session id issue: Different id for vf and developer console -


i facing following issue: on load of visualforce page making http callout internal salesforce page here facing authentication problem.

if running same http callout developer console getting successful response same code not working visualforce page. reason not working session id in developer console , visualforce domain different.

for fetching session id using "userinfo.getsessionid()"

i have tried {!$api.session_id} not working

my controller:

public 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);      } } 

rather setting cookie session try using authorization header.

request.setheader('authorization','bearer '+userinfo.getsessionid()); 

you need set ap1.salesforce.com endpoint in remote site settings.


if requesting pages within salesforce can use pagereference getcontent() method.

pagereference home = new pagereference('https://ap1.salesforce.com/home/home.jsp'); blob homeblob = home.getcontent(); string homecontent = homeblob.tostring(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -