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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:25:57+00:00 2026-06-11T16:25:57+00:00

Our environment has multiple web servers running behind a load balancer. If I modify

  • 0

Our environment has multiple web servers running behind a load balancer. If I modify my host file to go directly to a web server which will by-pass the load balancer, the HttpWebRequest works fine. If I remove the entry in my host file and let the request go through the load balancer it returns 404. However, if I perform the same request using a simple .html file on the same computer I am running the HttpWebRequest from it all works fine whether there is a entry in my host file or not.

Any ideas why it would work through the browser(Chrome) with the html file, but not an HttpWebRequest?

The request is a POST request which uploads a file and 3 other parameters.

Thanks in advance for any ideas.

EDIT: I tried setting my UserAgent to Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1 which is what Chrome sends when I use the html file.

Here is the function I’m using and currently works when no load balancer is in the mix:

private void PostFileToWebServer(byte[] file)
    {
        string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");

        var request = (HttpWebRequest)WebRequest.Create(_url);
        request.ContentType = "multipart/form-data; boundary=" + boundary;
        request.Method = "POST";
        request.KeepAlive = true;
        //Time in milliseconds
        request.Timeout = 1200000;

        request.Host = "ourdomain.com";
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1";
        request.CookieContainer = new CookieContainer(100000);

        var memStream = new MemoryStream();

        byte[] boundarybytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");

        string formDataTemplate = "\r\n--" + boundary + "\r\nContent-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";

        foreach(var key in _parameters.AllKeys)
        {
            string formData = string.Format(formDataTemplate, key, _parameters[key]);

            byte[] formDataBytes = Encoding.UTF8.GetBytes(formData);
            memStream.Write(formDataBytes, 0, formDataBytes.Length);
            memStream.Write(boundarybytes, 0, boundarybytes.Length);
        }

        string header = string.Format("Content-Disposition: form-data; name=\"file\"; filename=\"{0}\"\r\n Content-Type: application/octet-stream\r\n\r\n", _fileName);
        byte[] headerBytes = Encoding.UTF8.GetBytes(header);
        memStream.Write(headerBytes, 0, headerBytes.Length);

        memStream.Write(file, 0, file.Length);

        memStream.Write(boundarybytes, 0, boundarybytes.Length);

        request.ContentLength = memStream.Length;
        Stream requestStream = request.GetRequestStream();
        memStream.Position = 0;
        var tempBuffer = new byte[memStream.Length];
        memStream.Read(tempBuffer, 0, tempBuffer.Length);
        memStream.Close();

        requestStream.Write(tempBuffer, 0, tempBuffer.Length);
        requestStream.Close();

        var response = request.GetResponse();
        Stream stream2 = response.GetResponseStream();
        var reader2 = new StreamReader(stream2);

        System.Diagnostics.Debug.WriteLine(reader2.ReadToEnd());

        response.Close();
    }

EDIT: I commented out request.ContentType = "multipart/form-data; boundary=" + boundary; and it works with the load balancer. Anyone have an explanation for this?

  • 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-11T16:25:58+00:00Added an answer on June 11, 2026 at 4:25 pm

    Ok, me and Fiddler had a long conversation on the differences between the successful call and the unsuccessful call. Fiddler says the last boundary of the successful called sent from the browser has an extra “–” at the end of it. When I put that, all is well with the world and I can keep my Content-Type set as it is.

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

Sidebar

Related Questions

Our current environment has TFS on a single server installation: Windows Server 2003 Standard
I am planning to use php in an embedded environment. Our current web server
In our development environment each developer has their own dev server. Often times they
The code has a runtime dependency which is not available in our development environment
Our production environment runs 3 32-Bit Java 6 JVMs on each Windows 2003 server.
In our Production environment we have JBoss running in a clustered mode with 4+
This issue has come up three times in our environment. After installing the ClickOnce
In our environment, we share resources across multiple projects and platforms. When building for
We are working in a CI environment, with Enterprise Cruise running our builds. Developers
In our environment, we end up with multiple workspaces (runk plus multiple branches). We

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.