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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:24:11+00:00 2026-06-05T17:24:11+00:00

A friend show me this sample code to implement HTTP POST in C# and

  • 0

A friend show me this sample code to implement HTTP POST in C# and did work out in a WINFORM App:
http://www.terminally-incoherent.com/blog/2008/05/05/send-a-https-post-request-with-c/

And implemented in a METRO APP:

 // this is what we are sending
string post_data = "user=user@example.com&pass=example123";

// this is where we will send it
string uri = "http://app.proceso.com.mx/win8/login";

// create a request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";

// turn our request string into a byte stream
byte[] postBytes = Encoding.UTF8.GetBytes(post_data);

// this is important - make sure you specify type this way
request.ContentType = "application/x-www-form-urlencoded";
Stream requestStream = await request.GetRequestStreamAsync();

// now send it
requestStream.Write(postBytes, 0, postBytes.Length);

// grab te response and print it out to the console along with the status code
WebResponse response = await request.GetResponseAsync();
//var a = new StreamReader(response.GetResponseStream()).ReadToEnd();
StreamReader requestReader = new StreamReader(response.GetResponseStream());
String webResponse = requestReader.ReadToEnd();

I realized, HttpWebRequest does not contain ProtocolVersion and is throwing me this error in this line:

WebResponse response = await request.GetResponseAsync();
// ERROR: The remote server returned an error: (417) Expectation Failed.

I guess the last property is the solution. How can I solve this problem?
Thanks in advance

  • 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-06-05T17:24:13+00:00Added an answer on June 5, 2026 at 5:24 pm

    I recently wrote a small function to handle the posting of trivial data to a server.

    private struct HttpPostParam
    {
        private string _key;
        private string _value;
    
        public string Key { get { return HttpUtility.UrlEncode(this._key); } set { this._key = value; } }
        public string Value { get { return HttpUtility.UrlEncode(this._value); } set { this._value = value; } }
    
        public HttpPostParam(string key, string value)
        {
            this._key = key;
            this._value = value;
        }
    };
    
    private static string PostTrivialData(Uri page, HttpPostParam[] parameters)
    {
        string pageResponse = string.Empty;
        try
        {
            var request = (HttpWebRequest)WebRequest.Create(page); //create the initial request.
            request.Method = WebRequestMethods.Http.Post; //set the method
            request.AllowAutoRedirect = true; //couple of settings I personally prefer.
            request.KeepAlive = true;
            request.ContentType = "application/x-www-form-urlencoded";
    
            //create the post data.
            byte[] bData = Encoding.UTF8.GetBytes(string.Join("&", Array.ConvertAll(parameters, kvp => string.Format("{0}={1}", kvp.Key, kvp.Value))));
            using (var reqStream = request.GetRequestStream())
                reqStream.Write(bData, 0, bData.Length); //write the data to the request.
    
            using (var response = (HttpWebResponse)request.GetResponse()) //attempt to get the response.
                if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.NotModified) //check for a valid status (should only return 200 if successful)
                    using (var reader = new System.IO.StreamReader(response.GetResponseStream()))
                        pageResponse = reader.ReadToEnd();
        }
        catch (Exception e)
        {
            /* todo: any error handling, for my use case failing gracefully was all that was needed. */
        }
        return pageResponse;
    }
    

    Essentially it posts the value pairs defined in the “parameters” argument. Will require a reference and import of the System.Web namespace to compile.

    I just tested it with your website and got a response back:

    HttpPostParam[] httpparams = {
                                    new HttpPostParam("user", "censored@email.com"),
                                    new HttpPostParam("pass", "example123")
                                 };
    string response = PostTrivialData(new Uri("http://app.proceso.com.mx/win8/login"), httpparams);
    

    Let me know if there’s any issues.

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

Sidebar

Related Questions

I'm working on this site www.annapogossova.com for a friend. Currently the menu navigation is
Getting the following error when implementing this calendar gem. NoMethodError in Users#show Showing /Users/nelsonkeating/Desktop/ReminDeal/app/views/users/show.html.erb
A friend of mine with the iphone OS4 has pointed out that my app
A friend asked me for help on building a query that would show how
My friend and I were discussing the other day which style of code is
My friend done this below coding for custom control <a href=javascript:__doPostBack('id','msg');>click</a> now i want
I can't for the life of me figure out why this is happening. This
This is a tricky question to ask. A friend of mine seeks help, and
Special thanks to Rex M for this bit of wisdom : public IEnumerable<Friend> FindFriends()
http://www.sonikastudios.com/blog/company-news/real-estate-website-design-development-vancouver/ So I got the same code installed for this post as the other

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.