java - Google custom search engine android not accepting %20 or white space -


edit 2

found error passing invalid invalid parameter remebered tryiong out stuff.

sorry trouble guys

i using google custom search engine first time , far every thing fine. however, when try send query item has white space search engine returns bad request response eg

    myurl = (customsearchengineurl + api_key + "&cx=" + cxkey + "&q="             + q.replace(" ", "%20") + "&searchtype=" + searchtype             + "&imgtype=" + imgtype + "&imgsize=" + imgsize + "&num=20&alt=json"); 

this returns this

 com.google.api.client.http.httpresponseexception: 400 bad request 

edit

i took advice of 323go , tried encoding q , how implemented

string encodedparms = null;     try {         encodedparms = urlencoder.encode(q, "utf-8");     } catch (unsupportedencodingexception e1) {         // todo auto-generated catch block         e1.printstacktrace();     }     myurl = (customsearchengineurl + api_key + "&cx=" + cxkey + "&q="             + encodedparms + "&searchtype=" + searchtype + "&imgtype="             + imgtype + "&imgsize=" + imgsize + "&num=20&alt=json");      log.d(tag, myurl);      httprequestfactory httprequestfactory = createrequestfactory(http_transport);      httprequest request;     try {         request = httprequestfactory.buildgetrequest(new genericurl(myurl));         string response = streamtostring(request.execute().getcontent());     } catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();     } 

in log got url

https://www.googleapis.com/customsearch/v1?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-w&cx=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&q=sunway+lagoon+theme+park&searchtype=image&imgtype=photo&imgsize=xxlarge&num=20&alt=json 

i still got same bad request error

please can tell me doing worng

why dont add "+" between words, had same issue
"word1 word2" - response 400 - bad request
"word1+word2" - response 2000 - bad request


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -