Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. String apiUrl = "url";
  2. String wsUser = "YourWSUser";
  3. String wsPassword = "YourWSPassword";
  4.  
  5. CredentialsProvider provider = new BasicCredentialsProvider();
  6. UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(wsUser, wsPassword);
  7. provider.setCredentials(AuthScope.ANY, credentials);
  8.  
  9. HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
  10.  
  11.  
  12. HttpPost httpRequest = new HttpPost(apiUrl);
  13. httpRequest.addHeader("Content-Type", "application/json");
  14. httpRequest.setEntity(new StringEntity(paymentRequest.toString(), "UTF-8"));
  15. HttpResponse httpResponse = client.execute(httpRequest);
  16. String paymentResponse = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
  17.  
  18. HttpRequest req = new HttpRequest();
  19.  
  20. req.setEndpoint(apiUrl);
  21. req.setMethod('GET');
  22.  
  23. Blob headerValue = Blob.valueOf(username + ':' + password);
  24. String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
  25. req.setHeader('Authorization', authorizationHeader);
  26.  
  27. req.setHeader('Content-Type', 'application/json');
  28. req.setBody(generator.getAsString());
  29. req.setTimeout(60000);
  30.  
  31.  
  32. Http http = new Http();
  33. HTTPResponse res = http.send(req);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement