Hi All,
I am trying to send the data as json to external api and for that I am trying to set credentials on header but getting 401 error as response uaing below code
httpHeader.Add("Authorization: API Key keyname keyvalue") also attached the postman image keyname and key value are set to the blacked out values.
Can you please let me know how to fix this?
try
{
new InteropPermission(InteropKind::ClrInterop).assert();
httpHeader = new System.Net.WebHeaderCollection();
request = System.Net.WebRequest::Create(_url);
utf8 = System.Text.Encoding::get_UTF8();
bytes = utf8.GetBytes(_json);
request.set_Method(_method);
httpHeader.Add("Authorization: API Key keyname keyvalue");
request.set_Headers(httpHeader);
request.ContentType = 'application/json';
request.set_ContentLength(bytes.get_Length());
requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.get_Length());
response = request.GetResponse();
responseStream = response.GetResponseStream();
streamReader = new System.IO.StreamReader(responseStream);
responseJson = streamReader.ReadToEnd();
info(responseJson);
}
catch (Exception::CLRError)
{
ex = CLRInterop::getLastException().GetBaseException();
error(ex.get_Message());
}
requestStream.Close();
streamReader.Close();
responseStream.Close();
response.Close()

Thanks