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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:48:09+00:00 2026-05-16T05:48:09+00:00

I am trying to add document to the index using c# (xml) but I

  • 0

I am trying to add document to the index using c# (xml) but I am always getting error 400 (Bad request). Any ideas what I am doing wrong?

Code:

    private static string GetXml()
    {
        XDocument document = new XDocument(
            new XDeclaration("1.0", "UTF-8", "yes"),
            new XElement("add",
                new XElement("doc",
                    new XElement("field",
                        new XAttribute("name", "employeeId"),
                        new XText("05991")),
                    new XElement("field",
                        new XAttribute("name", "skills"),
                        new XText("Perl"))
                    )
                )
            );
        return document.ToString(SaveOptions.DisableFormatting);
    }

    private static void AddDocument()
    {
        string content = GetXml();
        HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://mysolrhost:8080/solr/update");
        request.Method = "POST";
        request.ContentType = "text/xml; charset=utf-8";
        byte[] byteArray = Encoding.UTF8.GetBytes(content);
        request.ContentLength = byteArray.Length;

        using (var requestStream = request.GetRequestStream())
        using (var sw = new StreamWriter(requestStream))
        {
            sw.Write(content);
        }
        WebResponse response = request.GetResponse();
        Console.WriteLine(((HttpWebResponse) response).StatusDescription);
    }

    public static void Main(string[] args)
    {
        AddDocument();
    }

Edit: the problem is solved (see the answer below).

Many thanks!

  • 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-16T05:48:09+00:00Added an answer on May 16, 2026 at 5:48 am

    Ah, silly me, I forgot to add field in the schema and this is the reason why i got 400. Everything is ok now.

    Many thanks!

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

Sidebar

Related Questions

Hi I am trying to add a custom field to the Schema.xml of Document
I'm trying to add an embedded document to an existing document field. I found
I'm trying to add an image to a generated html word document that is
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add a blank sample app for a rails tutorial to GitHub, but
I am trying to index a table in a database using Lucene. I use
so my code works fine by itself, but I'm trying to add some ajax
i'm trying to index an mp3 file with only one ID3 frame. using CLucene
I get this error when trying to add a record to my database: 2012-02-12
I'm trying to add dynamic content to my mvc application. I'm using Steven Sanderson

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.