byte[] jData = Encoding.UTF8.GetBytes(DATA);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });
//required this (header method not working)
CredentialCache crCache = new CredentialCache();
crCache.Add(new Uri(URL), "Basic", new NetworkCredential(uName, uPwd));
req.Credentials = crCache;
//required below, to enable cookies to carry authentication value over each request.
req.CookieContainer = new CookieContainer();
req.Accept = "application/json";
req.Method = "POST";
req.ContentType = "application/json;charset=utf-8";
req.Headers.Add(headerKey, headerValue);
req.GetRequestStream().Write(jData, 0, jData.Length);
using (HttpWebResponse res = (HttpWebResponse)req.GetResponse()) {
using (StreamReader strm = new StreamReader(res.GetResponseStream())) {
result = strm.ReadToEnd();
}
}
The above lines of code is a simple call to JSon Web service. The issue is the call is failing after sometime with UnAuthorized error. So I need to log HttpWeRequest to a text file to see the entire request. This should include headers, authentication credentials and body.. Can I know how can the entire request be captured and written to a file.
Thanks