0

Python code to c# .net for HTTP Post to API

response = requests.post(auth_url, auth=('apitoken', api_token), data={'grant_type': 'client_credentials'})

response.raise_for_status()

access_token = response.json()['access_token']

auth_header = 'Bearer ' + access_token

header = {'Authorization': auth_header}

3
  • Feel free to tag me (@john) if this doesn't answer your question. Commented Jun 13, 2019 at 1:44
  • @John can please let me know to access this peace of code access_token = response.json()['access_token'] Commented Jun 13, 2019 at 1:48
  • I recommend the Newtonsoft.Json library for that. See this example. Specific to your question, the code might look like dynamic parsedResponse = JObject.Parse(responseString); var accessToken = parsedResponse.access_token;. Not that you should typically deserialize to C# objects, rather than dynamic, though I think in this case it's probably OK :) Commented Jun 13, 2019 at 1:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.