TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abdalla Omran
NA
334
32.4k
a Problem with POST Request in WebForms ?
Mar 16 2020 7:31 AM
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()
{
//List<WebShopWebTexte> webShopWebTextes = new List<WebShopWebTexte>();
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;
}
Reply
Answers (
1
)
Logic related task in MVC using Ajax
How to secure dll files in asp.net mvc?