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

HttpRequest, redirect not being followed

Greetings everyone,

I am a Apex newbie who is trying to tie in our newer SalesForce implementation into some legacy systems we have here in the office. I have created a PHP-based, RESTfull web service that allows outside clients (SalesForce in this case) to do CRUD operations on some data sets we have locally. Up to a point, everything was working perfectly. I was able to have my web service return a test message, which my Apex class successfully returned to me in an email. This all changed when I started using mod_rewrite on the web services end.


I have all requests for URLs of a certain format redirecting to a single index page, where the request is handled by reading in the URL the user actually navigated to (handled by mod_rewrite). Example: user goes tohttp://myrestdomain/service/rest/application/opsdashboard/campaign/1234 but the user is really sent to http://myrestdomain/service/rest/index.php. All of this is working great in a web browser. However, when I use HttpRequest and set my endpoint, Apex returns nothing. If I do a getStatus() on the HttpResponse object I get a Status=Moved Temporarily, StatusCode=302.


Here is a code sample, it is really really basic. The variable TheResponse in this case is always an empty string because of the 302 I keep getting.


Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint('http://myrestserverdomain/service/rest/application/opsdashboard/campaign/1234'); req.setMethod('GET'); HttpResponse res = h.send(req); String TheResponse = res.getBody();


If you guys could help or even just point me in some direction I would be incredibly grateful.


I should point out that the URL I have listed above is correct aside from me taking out the domain we are using. Using that URL verbatim will not work.


Thanks in advance. - Brett

Message Edited by BrettDouglas on 12-16-2009 03:03 PM
Message Edited by BrettDouglas on 12-16-2009 05:02 PM

Hey Brett.. I'm also facing the same issue what you have faced while getting response from googledocs. Did you get any siolution for your issues?


This was quite some time ago, and the project that I was working on more or less got abandoned (it was more or less an R/D thing anyway).


If memory serves though, I did end up talking with a member of their tech team who essentially told me that there isn't native support for digesting RESTfull resources, because Apex will not honor the redirects that need to happen on the service being queried. Again, my memory is fuzzy but I remember coming to the conclusion that it would require my Apex code to know things about the REST service it shouldn't have to (in other words it would have to know where to send its request when the server should handle that on it own based on the URL and Apex should just follow along [hope that makes sense]).


I have gotten word that they are coming out with a new Rest based API. I do not know if that will also include better support for the digesting of external REST reources or not, although I am hoping it will.


Here is a link to the upcoming webinar:


Hope this helps.