title: Could not connect to Solr Application through JAVA
body: <p>I have searched this question on this forum and found many answer but none of he answer is solving my problem
  I want to connect to Solr application(verion 6.1.0) through java but it is giving me error.
  My code is :</p>
  
  <pre><code>import org.apache.solr.client.solrj.SolrClient;
  import org.apache.solr.client.solrj.SolrQuery;
  import org.apache.solr.client.solrj.impl.HttpSolrClient;
  import org.apache.solr.client.solrj.response.QueryResponse;
  public class solrConnection {   
      public void solrConnectionTest()  {
      try{
      String baseURL = "http://"IP-Address":8983/solr/#/test1/test2";
      @SuppressWarnings("deprecation")
      SolrClient solr = new HttpSolrClient(baseURL);  
      SolrQuery query = new SolrQuery(":");   
      query=new SolrQuery();
      query.set("qt", "/select");
      query.set("q", "sample test");
      query.set("wt", "json");
      QueryResponse response = solr.query(query);
      System.out.println("Response is : "+response);
      System.out.println("Program executed successfully");
      }catch(Exception e){
          e.printStackTrace();
      }   
      }
  }
  
  Error is: 
  
  
  org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://"IP-Address":8983/solr/#/test1/test2: Expected mime type application/octet-stream but got text/html. &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
  &lt;html&gt;
  
  &lt;!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
  
  http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  --&gt;
  
  &lt;head&gt;
  
    &lt;title&gt;Solr Admin&lt;/title&gt;
  
    &lt;link rel="icon" type="image/ico" href="img/favicon.ico?_=4.8.1"&gt;
  
    &lt;link rel="stylesheet" type="text/css" href="css/styles/common.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/analysis.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/cloud.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/cores.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/dashboard.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/dataimport.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/files.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/index.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/java-properties.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/logging.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/menu.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/plugins.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/documents.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/query.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/replication.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/schema-browser.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/styles/threads.css?_=4.8.1"&gt;
    &lt;link rel="stylesheet" type="text/css" href="css/chosen.css?_=4.8.1"&gt;
  
    &lt;meta http-equiv="x-ua-compatible" content="IE=9"&gt;
  
    &lt;script type="text/javascript"&gt;
  
    var app_config = {};
  
    app_config.solr_path = '\/solr';
    app_config.core_admin_path = '\/admin\/cores';
  
    &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
    &lt;div id="wrapper"&gt;
  
      &lt;div id="header"&gt;
  
        &lt;a href="./" id="solr"&gt;&lt;span&gt;Apache SOLR&lt;/span&gt;&lt;/a&gt;
  
        &lt;p id="environment"&gt;&amp;nbsp;&lt;/p&gt;
  
      &lt;/div&gt;
  
      &lt;div id="main" class="clearfix"&gt;
  
        &lt;div id="init-failures"&gt;
  
            &lt;h2&gt;SolrCore Initialization Failures&lt;/h2&gt;
            &lt;ul&gt;&lt;/ul&gt;
            &lt;p&gt;Please check your logs for more information&lt;/p&gt;
  
        &lt;/div&gt;
  
        &lt;div id="content-wrapper"&gt;
          &lt;div id="content"&gt;
  
            &amp;nbsp;
  
          &lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div id="menu-wrapper"&gt;
          &lt;div&gt;
  
            &lt;ul id="menu"&gt;
  
              &lt;li id="index" class="global"&gt;&lt;p&gt;&lt;a href="#/"&gt;Dashboard&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
  
              &lt;li id="logging" class="global"&gt;&lt;p&gt;&lt;a href="#/~logging"&gt;Logging&lt;/a&gt;&lt;/p&gt;
                &lt;ul&gt;
                  &lt;li class="level"&gt;&lt;a href="#/~logging/level"&gt;Level&lt;/a&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
  
              &lt;li id="cloud" class="global optional"&gt;&lt;p&gt;&lt;a href="#/~cloud"&gt;Cloud&lt;/a&gt;&lt;/p&gt;
                &lt;ul&gt;
                  &lt;li class="tree"&gt;&lt;a href="#/~cloud?view=tree"&gt;Tree&lt;/a&gt;&lt;/li&gt;
                  &lt;li class="graph"&gt;&lt;a href="#/~cloud"&gt;Graph&lt;/a&gt;&lt;/li&gt;
                  &lt;li class="rgraph"&gt;&lt;a href="#/~cloud?view=rgraph"&gt;Graph (Radial)&lt;/a&gt;&lt;/li&gt;
                  &lt;li class="dump"&gt;&lt;a href="#/~cloud"&gt;Dump&lt;/a&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
  
              &lt;li id="cores" class="global"&gt;&lt;p&gt;&lt;a href="#/~cores"&gt;Core Admin&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
  
              &lt;li id="java-properties" class="global"&gt;&lt;p&gt;&lt;a href="#/~java-properties"&gt;Java Properties&lt;/a&gt;&lt;/li&gt;
  
              &lt;li id="threads" class="global"&gt;&lt;p&gt;&lt;a href="#/~threads"&gt;Thread Dump&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
  
            &lt;/ul&gt;
  
            &lt;div id="core-selector"&gt;
              &lt;div id="has-cores"&gt;
                &lt;select data-placeholder="Core Selector"&gt;&lt;/select&gt;
              &lt;/div&gt;
              &lt;p id="has-no-cores"&gt;&lt;a href="#/~cores"&gt;
                No cores available
                &lt;span&gt;Go and create one&lt;/span&gt;
              &lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
            &lt;div id="core-menu"&gt;
              &lt;ul&gt;&lt;/ul&gt;
            &lt;/div&gt;
  
          &lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div id="meta"&gt;
  
          &lt;ul&gt;
  
            &lt;li class="documentation"&gt;&lt;a href="http://lucene.apache.org/solr/"&gt;&lt;span&gt;Documentation&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li class="issues"&gt;&lt;a href="http://issues.apache.org/jira/browse/SOLR"&gt;&lt;span&gt;Issue Tracker&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li class="irc"&gt;&lt;a href="http://webchat.freenode.net/?channels=#solr"&gt;&lt;span&gt;IRC Channel&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li class="mailinglist"&gt;&lt;a href="http://wiki.apache.org/solr/UsingMailingLists"&gt;&lt;span&gt;Community forum&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li class="wiki-query-syntax"&gt;&lt;a href="http://wiki.apache.org/solr/SolrQuerySyntax"&gt;&lt;span&gt;Solr Query Syntax&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
          &lt;/ul&gt;
  
        &lt;/div&gt;
  
      &lt;/div&gt;
  
    &lt;/div&gt;
  
    &lt;div id="connection_status"&gt;
  
      &lt;span&gt;Connection lost &amp;hellip;&lt;/span&gt;
  
    &lt;/div&gt;
  
    &lt;script type="text/javascript"&gt; var require = { urlArgs: '_=4.8.1' }; &lt;/script&gt;
    &lt;script src="js/require.js?_=4.8.1" data-main="js/main"&gt;&lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
      at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:558)
      at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:259)
      at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:248)
      at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:149)
      at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:942)
      at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:957)
      at roughwork.solrConnection.solrConnectionTest(solrConnection.java:36)
      at roughwork.solrConnection.main(solrConnection.java:47)
  </code></pre>