Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String apiUrl = "url";
- String wsUser = "YourWSUser";
- String wsPassword = "YourWSPassword";
- CredentialsProvider provider = new BasicCredentialsProvider();
- UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(wsUser, wsPassword);
- provider.setCredentials(AuthScope.ANY, credentials);
- HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
- HttpPost httpRequest = new HttpPost(apiUrl);
- httpRequest.addHeader("Content-Type", "application/json");
- httpRequest.setEntity(new StringEntity(paymentRequest.toString(), "UTF-8"));
- HttpResponse httpResponse = client.execute(httpRequest);
- String paymentResponse = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
- HttpRequest req = new HttpRequest();
- req.setEndpoint(apiUrl);
- req.setMethod('GET');
- Blob headerValue = Blob.valueOf(username + ':' + password);
- String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
- req.setHeader('Authorization', authorizationHeader);
- req.setHeader('Content-Type', 'application/json');
- req.setBody(generator.getAsString());
- req.setTimeout(60000);
- Http http = new Http();
- HTTPResponse res = http.send(req);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement