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 6002793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:01:46+00:00 2026-05-23T01:01:46+00:00

I am trying to implement a very basic system from my C# .NET application

  • 0

I am trying to implement a very basic system from my C# .NET application that sends the IP address of the machine to authenticate.php on my web server. The php page will check this IP address against a database and either respond back with “yes” or “no”.

It has been a long time since I worked with PHP, and I am a little bit confused. Here is what my .NET function looks like.

public static bool IsAuthenticated()
{
    string sData = getPublicIP();
    Uri uri = new Uri("http://www.mysite.com/authenticate.php");
    if (uri.Scheme == Uri.UriSchemeHttp)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
        request.Method = WebRequestMethods.Http.Post;
        request.ContentLength = sData.Length;
        request.ContentType = "application/x-www-form-urlencoded";

        // POST the data to the authentication page
        StreamWriter writer = new StreamWriter(request.GetRequestStream());
        writer.Write(sData);
        writer.Close();

        // Retrieve response from authentication page
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string sResponse = reader.ReadToEnd();
        response.Close();

        if (sResponse == "yes")
        {
            Console.WriteLine("Authentication was Successful.");
            return true;
        }
        else
        {
            Console.WriteLine("Authentication Failed!");
            return false;
        }
    }
}

So would the POST variable be $_POST[‘sData’]; and how do I respond back to my application with the result?

  • 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-23T01:01:47+00:00Added an answer on May 23, 2026 at 1:01 am

    Assuming the value of sData is (say) “10.1.1.1” then you’re currently not posting proper form data in the first place. The name of the variable isn’t part of the text written by

     writer.Write(sData);
    

    You need to do something like:

     string postData = "ipaddress=" + sData;
    

    and then use the ipaddress form parameter within your PHP.

    Note also that you should be giving the binary content length, which may not be the same as the string length in characters. Of course it’s okay if the string here is entirely ASCII, which I’d expect if it’s an IP address… but it’s worth bearing in mind for other uses. (Likewise you would normally need to bear in mind any characters which need special encoding.)

    Also note that it would be better to use using statements for the StreamWriter, HttpResponse etc, to make sure that everything gets closed even if an exception is thrown.

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

Sidebar

Related Questions

I am trying to implement a very basic before advice with Spring.Net, that just
I'm trying to implement a basic tagging system with hibernate. The problem is that
This is a very basic example of what I am trying to implement in
I'm trying to decide how to implement a very basic licensing solution for some
I'm trying to implement search functionality in my app, which is very basic at
I'm trying to implement my first Facebook application, and I'm stuck on the very
I am very new to OOP styled PHP, and I am trying to implement
Am trying to implement a generic way for reading sections from a config file.
We are trying to implement a REST API for an application we have now.
I am trying to implement AJAX in my Google App Engine application, and so

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.