Click here to Skip to main content
15,868,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python Code

import requests

url = "https://www.xyz.com/FACD/"
session = requests.session()
r = session.get(url, auth=("krishp","abcdef1"))
print(r.statuscode)
print(r.cookies) #has cookies that authenticates subsequent reqeusts

r = session.get(url + "api/v1/products")
print(r.statuscode)
print(r.text)

What I have tried:

C# Code
I ran the below code and even though status is OK, my session is not authenticated as I don't see the cookies
that I see in the above Python code. Please let me know what I'm doing wrong as I'm new to Rest API calls in C#

var request = HttpRequest.Create("https://www.xyz.com/FACD/");
request.Method = "GET";
request.Credentials = new NetworkCredentials("krishp", "abcdef1")
request.ContentType = "application/x-www-forum-urlencoded";

var response = (HttpWebResponse)request.GetResponse()
var statusCode = response.StatusCode;
Posted
Updated 23-Jul-21 2:52am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900