Hello all,
I have a scenario to get/post api httprequest with 3 headers (client key, client secret, api key). I tried with the below code.
and i am not sure how to pass the headers with 3 component. It gives me the error /The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel/.
After debugging, the error is being thrown from RetailCommonWebAPI(getResponse) method.
class TestRequest
{
public static void main(Args _args)
{
//Creaates a request
RetailWebRequest webRequest = TestRequest::getSalesRequest();
RetailCommonWebAPI webApi = RetailCommonWebAPI::construct();
RetailWebResponse webResponse = webApi.getResponse(webRequest);
str responseData = webResponse.parmData();
if (webResponse.parmHttpStatus() == 200)
{
//logic
}
}
public static RetailWebRequest getSalesRequest()
{
URL url = strLTrim(*********);
str method = 'POST';
str contentType = @'application/json';
str requestBody = '{/Value0/: ####, /Value1/: ####}';
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
RetailWebRequest webRequest = RetailWebRequest::newUrl(url);
System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
headers.add(/Client_key/, /****/);
headers.add(/Client_Secret/, /********/);
headers.add(/API_Key/, /*************/);
webRequest.parmMethod(method);
webRequest.parmHeader(headers);
webRequest.parmContentType(contentType);
webRequest.setContentBytes(encoding.GetBytes(requestBody));
return webRequest;
}
}
Please let me know how to call header and any fix for the error message.