You can use the following code for calling the external URL and posting the request. You can change the POST method to GET,PUT or DELETE depending on your requirement,
// CREATE REQUEST
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://xyz.com);
Request.Method = "POST";
Request.ContentType = "application/json";
Request.Headers.Add(string.Format("Authorization:{0}", "AVCNV"));
Stream dataStream = Request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
// GET RESPONSE
try
{
WebResponse Response = Request.GetResponse();
HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
{
var error = "Unauthorized - need new token";
}
else if (!ResponseCode.Equals(HttpStatusCode.OK))
{
var error = "Response from web service isn't OK";
}
StreamReader Reader = new StreamReader(Response.GetResponseStream());
string responseLine = Reader.ReadToEnd();
Reader.Close();
return true;
}
catch (Exception ex)
{
}
return false;