Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public with sharing class AS_httpSyncToWordpress {
  2.  
  3.  
  4. @future (callout=true)
  5. public static void sendAPIRequestInsert(Set<Id> setAllId) {
  6. Contact[] allContact= [Select Id,FirstName,LastName,Email FROM Contact where ID IN :setAllId];
  7.  
  8. HttpRequest req = new HttpRequest();
  9. HttpResponse res = new HttpResponse();
  10. Http http = new Http();
  11.  
  12. String username = 'sampleusername';
  13. String password = 'samplepassword';
  14.  
  15. Blob headerValue = Blob.valueOf(username + ':' + password);
  16. String authorizationHeader = 'BASIC ' +
  17. EncodingUtil.base64Encode(headerValue);
  18. req.setHeader('Authorization', authorizationHeader);
  19.  
  20. // below is just a sample endpoint
  21. req.setEndpoint('https://mysampleEndpoint.com:8080/wp-json/myApi/v1/create_contact');
  22. req.setMethod('POST');
  23. // req.setHeader('Content-Length','2004');
  24. req.setHeader('Content-Type', 'application/json');
  25. req.setBody(JSON.serialize(allContact));
  26. // req.setCompressed(true); // otherwise we hit a limit of 32000
  27. System.debug('allContact : ' + allContact);
  28. System.debug('REQUEST : ' + req);
  29. try {
  30. res = http.send(req);
  31. System.debug('RESPONSE wew ' + res.getBody());
  32. } catch(System.CalloutException e) {
  33. System.debug('Callout error: '+ e);
  34. System.debug(res.toString());
  35. }
  36.  
  37. }
  38. }
  39.  
  40. System.HttpRequest retrying request in response to handshake failure: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement