7 Replies ・ Started by mairyu at 2017-11-05 20:36:08 UTC ・ Last reply by Kimtaro Admin at 2017-12-27 00:02:50 UTC

API request fails when I use Kanji for keyword, but works for Romaji

Starting 2-3 weeks ago, my search results for Kanjis came up empty on my Android App (which uses your API), I finally ran the debugger and see that the 'getInputStream' on the httpURLConnection triggers an exception.
I just saw that you moved to https, but don't think that's the issue since the Romaji based one works just fine.
Will convert to https anyway, but maybe you or someone in the forum already know what's wrong :-)

Kimtaro Admin at 2017-11-05 23:00:42 UTC

The HTTPS support was turned on just today, so that is unlikely to be the culprit, and as you say the romaji works.

I haven’t made any changes to the api in a while, but it sounds like it could possibly be an encoding issue.

Can you post the exact url your app is requesting?

mairyu at 2017-11-07 17:05:22 UTC
                dictHTTPClient.setBASE_URL("http://jisho.org/api/v1/search/words?keyword=" + KeyWord);

before I dug deeper, just wanted to check if anything major changed 2-3 weeks ago.

Kimtaro Admin at 2017-11-07 20:06:45 UTC

@mairyu Thanks. Are you doing any encoding of the KeyWord variable before this line? Are you able to log the exact URL that is being sent by the dictHTTPClient library?

mairyu at 2017-11-09 03:18:18 UTC

hmm, I just ran in the emulator and it ran fine i.e. it fetched results with the kanji as search pattern. When I run on the phone, it fails.

it shows this in the Debug window for the URL


which gives me a nice JSON in the browser. I see the same for the phone debug, but get no data in return when I:

        String data = (dictHTTPClient.getHTTPData());

This all worked just fine 2 weeks ago or so, so I don't think I have to go into UTF decoding etc. I just concatenate the String to the URL and it works.
Now that I have the Emulator working, I can dig a bit deeper, no worries.

mairyu at 2017-11-26 04:18:09 UTC

still stuck on this, narrowed it down to a bad request:

11-25 20:15:16.645 8936-9734/com.mairyu.app.lingoflash I/LOG: (HTTP): BASE_URL http://jisho.org/api/v1/search/words?keyword=滝
11-25 20:15:17.295 8936-9734/com.mairyu.app.lingoflash I/LOG: (HTTP) - STATUS: Code 400
11-25 20:15:17.315 8936-9734/com.mairyu.app.lingoflash I/LOG: (HTTP) - RETRUN: >>> 400 Bad request
Your browser sent an invalid request.

I don't understand why the exact same request is okay when sent from emulator (or when I copy and paste it in the browser)

Must have something to do with the UTF decoding, but why would that have worked the entire year and suddenly break several weeks ago ...

mairyu at 2017-11-26 06:56:37 UTC


This did the trick:

                String encoded = KeyWord;

                    encoded = URLEncoder.encode(KeyWord, "UTF-8");

                catch(Exception e){}

                dictHTTPClient.setBASE_URL("http://jisho.org/api/v1/search/words?keyword=" + encoded);

not sure why it worked w/o this on the emulator or why it worked 2 month ago, but I'm finally back in a good place

Kimtaro Admin at 2017-12-27 00:02:50 UTC

@mairyu Sorry for not replying earlier, but I'm glad that you found the issue!

to reply.