0

I am trying to pass two set of value to same parameter in webclient querystring but its giving me error as - How to handle multiple values to same parameter ? Even i tried passing both values to same parameter but it did not worked.

 wc.QueryString.Add("wt", "json");                              
 wc.QueryString.Add("fq", domain + "&fq=" + orgs); // like this , but did not work           
 wc.QueryString.Add("indent", "true");    

The remote server returned an error: (400) Bad Request.

Looks like url is not forming correctly. if i pass only one value to fq (parameter) it works fine

using (WebClient wc = new WebClient())
            {
                wc.QueryString.Add("wt", "json");                              
                wc.QueryString.Add("fq", domain);
                wc.QueryString.Add("fq", orgs);
                wc.QueryString.Add("indent", "true");     
// This line gives error           
                data = wc.UploadValues(uri, "POST", wc.QueryString);

URL should look something like this -

https://abc:2100/solr/select?fq=domain:MCO&fq=org:US OR org:TH&q=John

But URL is coming as -

https://abc:2100/solr/select?fq=domain:MCO,org:US OR org:TH&q=John

How to get rid of this ?

Even after removing comma what is coming in querystring , it throws bad request

https://abc:7855/solr/newnew/select?fq=domain:Compl/GPO OR domain:FIU OR domain:FIU/FCRU OR domain:MCO&fq=org:00 OR org:01 OR org:99 OR org:AF OR org:AR OR org:AT OR org:AU OR org:BE OR org:BZ OR org:CA OR org:CH OR org:CN OR org:CZ OR org:D1 OR org:D2 OR org:D3 OR org:D4 OR org:DE OR org:DK OR org:E1 OR org:E2 OR org:E3 OR org:ES OR org:FI OR org:FR OR org:GB OR org:HK OR org:HU OR org:IN OR org:IT OR org:JP OR org:LU OR org:MX OR org:NL OR org:NO OR org:NZ OR org:P1 OR org:PL OR org:RU OR org:SE OR org:SG OR org:T1 OR org:TH OR org:TW OR org:US OR org:X1 OR org:X2 OR org:Z1 OR org:Z2&wt=json&q=tom&start=0&rows=20&indent=true
Bokambo
  • 4,204
  • 27
  • 79
  • 130
  • The Solr log should tell you exactly what the request URL was - check that to know what URL is actually being generated. – MatsLindh Sep 30 '18 at 20:21
  • In Solr i saw url is - https://abc:2100/solr/select?fq=domain:MCO,fq=org:US OR org:TH&q=John so what i did it i only passed one "fq" Parameter and appended all required url to it to avoid extra comma then also same error – Bokambo Sep 30 '18 at 20:47
  • Possible duplicate of [How to build WebClient querystring with duplicate keys?](https://stackoverflow.com/questions/17415169/how-to-build-webclient-querystring-with-duplicate-keys) – MatsLindh Oct 01 '18 at 06:51
  • I tried this but still it gives bad request , even after removing comma, is there any limitation on size of querystring..i will update querystring in my original question – Bokambo Oct 01 '18 at 16:17
  • What is the actual error given? My initial guess is that it's related to your `q` not having a field name present, and possibly no default search field set. Another guess could be the `/`, but it shouldn't have to be escaped as far as I remember. But Solr will give you a reason for the 400. – MatsLindh Oct 01 '18 at 17:11
  • The remote server returned an error: (400) Bad Request. q not having field name, what does it mean, q = Tom in my url you can see. What do you mean by default search ? – Bokambo Oct 01 '18 at 18:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181102/discussion-between-user662285-and-matslindh). – Bokambo Oct 01 '18 at 18:32

0 Answers0