Scenario: Hello, I have a cURL string which needs to be converted to Http request to be called from apex.
Problem: I am getting 400 Bad Request Error
cURL:
curl https://test.sagepay.com/api/v1/merchant-session-keys \
-u "integrationKey:integrationPassword" \
-H "Content-type: application/json" \
-X POST \
-d '{
"vendorName": "testVendor"
}'
Apex Http Request
req.setEndpoint('https://test.sagepay.com/api/v1/merchant-session-keys');
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
req.setBody('vendorName:testVendor');
Blob headerValue = Blob.valueOf(integrationKey +':' +IntegrationPassword);
String authorizationHeader = 'Basic ' + 'EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
Note: A similar question has already been posted previously: link here