Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7674467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:44:37+00:00 2026-05-31T16:44:37+00:00

I have to really ask this question as I donot know Python. Following are

  • 0

I have to really ask this question as I donot know Python.
Following are a few lines taken from this place. I would appreciate if someone guides me in translating the following to C#

#Step 1: Get a session key
servercontent = myhttp.request(baseurl + '/services/auth/login', 'POST',
                            headers={}, body=urllib.urlencode({'username':username, 'password':password}))[1]
sessionkey = minidom.parseString(servercontent).getElementsByTagName('sessionKey')[0].childNodes[0].nodeValue
print "====>sessionkey:  %s  <====" % sessionkey
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:44:38+00:00Added an answer on May 31, 2026 at 4:44 pm

    Here’s a quick-n-dirty translation:

    using System.Linq.Xml;
    using System.Net;
    using System.Collections.Generic;
    using System.Web;
    
    // ...
    var client = new WebClient();
    var parameters = new Dictionary<string, string> 
    { 
      { "username", username },
      { "password", password }
    };
    
    var result = client.UploadString(String.Format("{0}/services/auth/login", BaseUrl), UrlEncode(parameters));
    var doc = XDocument.Load(result);  // load response into XML document (LINQ)
    var key = doc.Elements("sessionKey").Single().Value // get the one-and-only <sessionKey> element.
    Console.WriteLine("====>sessionkey:  {0}  <====", key);
    // ...
    
    // Utility function: 
    private static string UrlEncode(IDictionary<string, string> parameters)
    {
      var sb = new StringBuilder();
      foreach(var val in parameters) 
      {
        // add each parameter to the query string, url-encoding the value.
        sb.AppendFormat("{0}={1}&", val.Key, HttpUtility.UrlEncode(val.Value));
      }
      sb.Remove(sb.Length - 1, 1); // remove last '&'
      return sb.ToString();
    }
    

    This code does a check to see that the response only has one sessionKey element, otherwise it’ll throw an exception if there’s 0, or more than 1. Then it prints it out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really hesitant to ask this question, since it's sure to have such a
I'm not really sure how to ask this question. Suppose I have a class
I really didn't know how to ask this question in a simple fashion. I
I am really sorry to ask this silly question. I have been onto this
I am not really sure how to ask this question. I have been teaching
Why I ask this question: I know there have been a lot of questions
I don't know if this question has been ask before. But I have a
I have a really dumb question if you don't mind me to ask :(
Im new to iPhone development and I have really taken this to me. I
I might be very stupid to ask this question. But I really hav no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.