I am trying to read API for example like "https://test......." with POST request and Basic authentication .
the POST request has Body with URL . i should pass url insaid a body to get json data back which i want to convert it into C# object but the Problem that i am getting always the erro 401 or 405 and i cant get the response .
my goal is to get the json data back but how could i pass the url which is in Body ? and why i am getting this erros 401,405 .
for any help i will be happy
- private string LoadHttpPageWithBasicAuthentication()
- {
-
- Uri myUri = new Uri("https://.......");
- WebRequest request = HttpWebRequest.Create(myUri);
- request.Method = WebRequestMethods.Http.Post;
-
- request.ContentType = "application/json";
-
- HttpWebRequest httpWebRequest = (HttpWebRequest)request;
-
- NetworkCredential myNetworkCredential = new NetworkCredential("++++", "++++");
-
- CredentialCache myCredentialCache = new CredentialCache();
- myCredentialCache.Add(myUri, "Basic", myNetworkCredential);
-
- httpWebRequest.PreAuthenticate = true;
- httpWebRequest.Credentials = myCredentialCache;
-
- WebResponse response = request.GetResponse();
-
- Stream responseStream = response.GetResponseStream();
-
- StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);
-
- string pageContent = myStreamReader.ReadToEnd();
-
- responseStream.Close();
-
- response.Close();
-
- return pageContent;
-
- }