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
Akira007Akira007 

url access from APEX code

Hi, everyone,

Can I access some url with http GET method and get and check  the response  code ( 200, 401 ..etc) from APEX code?
I'll appreciate very much if some one provide me the solution with sample cpde...

Regards

Akira

JimRaeJimRae
Look in the Apex documentation for HTTP Services Classes (page 264), there are some samples included as well.

Here is a real simple example:

Code:
public class AuthCallout {
 public void basicAuthCallout(){
  HttpRequest req = new HttpRequest();
  req.setEndpoint('http://www.yahoo.com');
  req.setMethod('GET');

  // Create a new http object to send the request object
  // A response object is generated as a result of the request
  Http http = new Http();
  HTTPResponse res = http.send(req);
  System.debug(res.getStatusCode());
 }
}

 

Akira007Akira007
Thank you very much for your response.
I will try it!

Regards

Akira Fujiwara