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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:35:33+00:00 2026-05-19T17:35:33+00:00

I am trying to rewrite some server php code which logs into a website,

  • 0

I am trying to rewrite some server php code which logs into a website, using the canonical HttpWebRequest usage found all over the net on C# sites:

HttpWebRequest BuildPOST(string url, string parameters)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "POST";
    byte[] bytes = Encoding.ASCII.GetBytes(parameters);
    Stream os = null;
    try
    { 
         request.ContentType = "application/x-www-form-urlencoded";
         equest.ContentLength = bytes.Length;
         os = request.GetRequestStream();
         os.Write(bytes, 0, bytes.Length); 
    }
    catch (WebException ex)
    {
         Console.WriteLine("{0} HttpPost: Request error", ex.Message);
    }
    finally
    {
         if (os != null)
         {
              os.Close();
         }
    }
    return request;
}

called using:

string login_url = "http://www.sailonline.org/community/accounts/login/";
string login_post_data = "next=/windy/run/{0}/&password={1}&username={2}";  // race, pwd, boat
HttpWebRequest req = BuildPOST(login_url, string.Format(login_post_data, race, pwd, user));

The original php is:

include 'phplib.php';

$url = "http://www.sailonline.org/community/accounts/login/";
$postdata = sprintf("next=/windy/run/%s/&password=%s&username=%s", $race, $key, $boat);
$html = get_pipe_output(build_post_url($url, $postdata));

However, the C# code does not generate the same response from the server as the php code. Instead I get a page asking for login details (which were correctly input in the post to begin with).

I am somewhat new to network programming, and just cannot seem to figure out why this is happeneing. I have snooped the packets from my code, the page serving the php and the original login page on the website in question and cannot see any difference betwen the requsts, only that the one issued from C# code does not have the expected response.
All I can think is perhaps the php functions do something I am unaware of ??

  • 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-19T17:35:34+00:00Added an answer on May 19, 2026 at 5:35 pm

    You need to create and set a CookieContainer on the request. Without that your request wont succeed. Looks like the page is sending cookies with the response.

    HTTP/1.1 200 OK
    Date: Mon, 31 Jan 2011 23:53:23 GMT
    Server: Apache
    Expires: Mon, 31 Jan 2011 23:53:23 GMT
    Vary: Cookie
    Last-Modified: Mon, 31 Jan 2011 23:53:23 GMT
    ETag: "ad806aa693ed8187c278f0fadfa92d01"
    Cache-Control: max-age=0
    Content-Type: text/html; charset=utf-8
    Set-Cookie:  sailonlinesid=bcc2b5fe9980df3e741e8fe7279d61d4; Domain=.sailonline.org; expires=Mon, 14-Feb-2011 23:53:23 GMT; Max-Age=1209600; Path=/
    Connection: close
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to rewrite URLs using mod_rewrite. It is enabled in httpd.conf and
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
I'm trying to upgrade from PHP 5.2.x to 5.3.2 on my server. Problem is,
I'm trying to figure something out. This is the code I'm using to hide
I am trying to create some Apache rewrite rules that shall be able to
Trying to install rattle on a windows server 2008 R2 64bit machine, using 64-bit
I'm trying to use URL rewrite in my new project. But I also need
I am trying to create a rewrite rule that accomplishes two things: Redirect (www.)?domain.com
I'm trying to redirect all requests to my domain to another domain using mod_rewrite

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.