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

  • Home
  • SEARCH
  • 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 96469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:49:11+00:00 2026-05-10T23:49:11+00:00

I am creating an application in .NET that will serve as a second UI

  • 0

I am creating an application in .NET that will serve as a second UI for my already-deployed Django app. For some operations users need to authenticate themselves (as Django users). I used a super-simple way to do this (without encrypting credentials for simplicity):-

Step 1. I created a django view that accepted the username and password through two HTTP GET parameters and passed them on to django.contrib.auth.authenticate() as keyword arguments. See the code below:

     def authentication_api(request, raw_1, raw_2):         user = authenticate(username=raw_1, password=raw_2)         if user is not None:             if user.is_active:                 return HttpResponse('correct', mimetype='text/plain')             else:                 return HttpResponse('disabled', mimetype='text/plain')         else:             return HttpResponse('incorrect', mimetype='text/plain')

Step 2. I called this using the following code in .NET. The ‘strAuthURL’ in the following representes a simple django URL mapped to the django view above:

     Dim request As HttpWebRequest = CType(WebRequest.Create(strAuthURL), HttpWebRequest)     Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)     Dim reader As StreamReader = New StreamReader(response.GetResponseStream())     Dim result As String = reader.ReadToEnd()     HttpWResp.Close()

This works flawlessly, although it is nothing more than a proof-of-concept.

Now I want to do this via HTTP POST so I have done the following: –

I created a django view for the doing authentication using POST data

     def post_authentication_api(request):         if request.method == 'POST':             user = authenticate(username=request.POST['username'], password=request.POST['password'])             if user is not None:                 if user.is_active:                     return HttpResponse('correct', mimetype='text/plain')                 else:                     return HttpResponse('disabled', mimetype='text/plain')             else:                 return HttpResponse('incorrect', mimetype='text/plain')

I have tested this using restclient and this view works as expected. However I can't get it to work from the .NET code below:

     Dim request As HttpWebRequest = CType(WebRequest.Create(strAuthURL), HttpWebRequest)     request.ContentType = 'application/x-www-form-urlencoded'     request.Method = 'POST'     Dim encoding As New UnicodeEncoding     Dim postData As String = 'username=' & m_username & '&password=' & m_password     Dim postBytes As Byte() = encoding.GetBytes(postData)     request.ContentLength = postBytes.Length     Try         Dim postStream As Stream = request.GetRequestStream()         postStream.Write(postBytes, 0, postBytes.Length)         postStream.Close()         Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)         Dim responseStream As New StreamReader(response.GetResponseStream(), UnicodeEncoding.Unicode)         result = responseStream.ReadToEnd()         response.Close()     Catch ex As Exception         MessageBox.Show(ex.ToString)     End Try

The server is giving me a 500 internal server error. My guess is that the POST request is not properly set up in .NET. So I basically need some guidance on how to call the django view from .NET sending POST data.

Thanks, CM

  • 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. 2026-05-10T23:49:11+00:00Added an answer on May 10, 2026 at 11:49 pm

    Looks ok to me. I recommend using Wireshark to see what your restclient is sending in the headers and and see what your app sending in the headers.

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

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Here's a solution. I checked this out in a test… May 11, 2026 at 2:33 pm
  • added an answer Your problem is that user-scoped settings are read by the… May 11, 2026 at 2:33 pm
  • added an answer Choose 'Disabled' from the Console dropdown (this disables all by… May 11, 2026 at 2:33 pm

Related Questions

I am creating a department picker form that is going to serve as a
Working inside the context of an ASP.NET application I am creating a page that
The issue is there is a database with around 20k customer records and I
I would like to be able to hide another application's window from the taskbar,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.