I am using Solr 4. I have a very long query to search for (URI too long). So I am using POST method with JSON request content to search using HttpWebRequest in C#. But getting error as "The remote server returned an error: (400) Bad Request.". I checked in Solr log which shows the error as "org.apache.solr.common.SolrException: Search requests cannot accept content streams". But everything is working in Solr 7. Is there any way to search in Solr 4 for very long query? Please help me.
Asked
Active
Viewed 202 times
1 Answers
0
Try changing the "Content-Type" header on the request
Changing it to "application/x-www-form-urlencoded" should do the trick.
See following link to set header on HttpWebRequest: Add custom header in HttpWebRequest
EDIT: Please make sure to use POST request. In URL only enter the end point and add the query as request body.

Ishan
- 154
- 1
- 1
- 9
-
Sorry, it did not work. I tried this : `HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);` `request.ContentType = "application/x-www-form-urlencoded";` `request.Method = "POST";` `HttpWebResponse response = (HttpWebResponse)request.GetResponse();` In Solr 7, it throws error as "The remote server returned an error: (414) URI Too Long". In Solr 4, it throws error as "The remote server returned an error: (400) Bad Request". – B Roy Oct 28 '21 at 11:03
-
It seems you are specifying the query in URL only. You can specify query in request body also. – Ishan Oct 28 '21 at 17:12
-
Please show me the way with example. As I have mentioned earlier that Solr 4 is not accepting content streams when I was sending request body in JSON format. – B Roy Nov 01 '21 at 07:43
-
Can you please specify the URL you are using? – Ishan Nov 07 '21 at 17:05
-
From the error it seems that you are entering your solr query in URL. In the code you shared in comments it shows that you are hitting a URL but I did not see what URL you are hitting. I also did not understand where you are setting the form body. Maybe if you can share the complete code snippet, I can help further. – Ishan Nov 07 '21 at 17:27