function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Puneet KhoslaPuneet Khosla 

Http request from browser works fine but not from apex

I have a http request (to an external system) which is returning a valid json response when I put it in browser, but when I try to use the http request from code, it doesn't work.

It further looks that when it returns, its actually taking to the salesforce Remote Authorization page, thus causing a redirect.

Is there are way to proceed further when this Redirect Authorization page is coming in apex or what do I need to pass in the http request (I added the Header Authorization : 'OAuth' + UserSessionid in the request from salesforce to the api.

Debug statement of Response.getBody();
==
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://test.salesforce.com/?ec=302&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource%3Dsdjfnsdjkfbjsdfbsdbfsdjhbfhsdbf'); }  else
if (window.location.replace){ 
window.location.replace('https://test.salesforce.com/?ec=302&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource%3D.............
==
VineetKumarVineetKumar
Has the endpoint been added under the remote site settings, for the HTTP request end point?
Puneet KhoslaPuneet Khosla
Yes it's already added.
VineetKumarVineetKumar
Ok, can you give me a bit of background of what is your requirement, perhaps I would be able to suggest something.
Puneet KhoslaPuneet Khosla
Requirement is 

I am calling php service from apex using http request.
I am giving the end point, parameters, etc.

When I initiate the http request from apex, it calls the php service.
php service tries to authenticate from salesforce (for a genuine request) and thus sends the request to get authorization

/services/oauth2/authorize?response_type=code&client_id=
However this is where Salesforce gets stuck at the RemoteAccessAuthorizationPage in the response.
 
VineetKumarVineetKumar
seems like you are missing some parameters while making the call, not sure unless I see your actual code
I suppose you would have already gone through few posts, can you refer the below post and check your code with it?
http://salesforce.stackexchange.com/questions/8208/bypassing-remoteaccessauthorizationpage-when-using-a-remote-application