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
hegde_hegdekhegde_hegdek 

Not able to authorizae a https site using HttpRequest

Hello Friends,

I am not able to authorization error,when i do a rest call using the HttpRequest .should i use certificate,if so how do i handle it through coding

here is my cod example

 

public void basicAuthCallout(){HttpRequest req = new HttpRequest();
     req.setEndpoint(url);
     req.setMethod('POST');  
      String username = username;
     String password = password;
     String const_data = '<?xml version="1.0" encoding="UTF-8"?><activity name="New activity via salesforce"></activity>';
     Blob headerValue = Blob.valueOf(username + ':' + password);
     String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);
     req.setHeader('Authorization', authorizationHeader);
     req.setHeader('Accept', 'application/xml');
     req.setBody(const_data);  
       
     // 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);
      res = http.send(req);
     System.debug(res.getBody());
   }

Best Answer chosen by Admin (Salesforce Developers) 
hegde_hegdekhegde_hegdek
 this solved,the problem was the case sensitiveness of the key work Basic,i had put basic as caps only the first letter should be caps

All Answers

hegde_hegdekhegde_hegdek
 this solved,the problem was the case sensitiveness of the key work Basic,i had put basic as caps only the first letter should be caps
This was selected as the best answer
mtbclimbermtbclimber
Thanks for following up and closing this thread out. :)