Below is the way I did. Using BASIC Authentication and XML data as the payload. Happy Coding :)
SomeClass{
private NetworkCredential credentials = null;
private HttpClientHandler handler = null;
SomeClass(){ //Constructor
credentials = new NetworkCredential("ID", "PASS");
handler = new HttpClientHandler { Credentials = credentials};
}
public async Task<HttpResponseMessage> PutMessage(your data)
{
var root= new
{
rootObj = data
};
var jsonObj = JsonConvert.SerializeObject(root);
var doc = JsonConvert.DeserializeXmlNode(jsonObj);
HttpResponseMessage response = null;
try
{
var httpContent = new StringContent(doc.InnerXml.ToString(), Encoding.UTF8, "application/xml");
HttpClient httpClient = new HttpClient(handler);
response = await httpClient.PostAsync(APIURL, httpContent);
if (!response.IsSuccessStatusCode)
return response;
}
catch (Exception ex)
{
return "Return Error Message";
}
}
}