2

I have a this api from aparat site . I use this method for search

http://www.aparat.com/etc/api/videoBySearch/text/[نوروز]

I should fill last parameter with my editText value . For getting json . If i send english string it worked . But if i send unicode string like persian , It can't work and when i logging that , it say

java.lang.RuntimeException: Bad URL null

This is my JsonResponse method :

   //this method call when search button pressed !
    private void sendJsonRequest() {
        String rawQuery = edtsearchQuery.getText().toString();
       ==> String first_url =   "http://www.aparat.com/etc/api/videoBySearch/text/"+ rawQuery;



        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, first_url, (String) null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                parseJsonResponse(response);
                adapter.notifyDataSetChanged();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d("onErrorResponseSenJsReq" , error.getMessage());
            }
        });
        AppController.getInstance().addToRequestQueue(request);
    }
kiana rahimi
  • 246
  • 4
  • 16

1 Answers1

3

Instead of sending نوروز in URL use URLEncoder for encoding it before appending it in main URL:

String strSearchQuery= URLEncoder.encode(rawQuery, "utf-8");
String first_url="http://www.aparat.com/etc/api/videoBySearch/text/"
                                                        +strSearchQuery;
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • according to your sulution . it's replaced but it still have a problem and when i enter the value of mu url it worked on chrome . but it didnt work on mobile . – kiana rahimi Feb 11 '16 at 13:29
  • 1
    While `String strSearchQuery= URLEncoder.encode(rawQuery, "utf-8");` is more readable, it is worth knowing that it is equivalent to `String strSearchQuery= URLEncoder.encode(rawQuery);` – Rany Albeg Wein Feb 11 '16 at 13:30
  • with english string http://www.aparat.com//etc/api/videobysearch/text/b/curoffset/20 and with unicode string http://www.aparat.com//etc/api/videobysearch/text/%D9%86%D9%88%D8%B1%D9%88%D8%B2/curoffset/20 – kiana rahimi Feb 11 '16 at 13:30
  • 1
    @kianarahimi: but `http://www.aparat.com/etc/api/videoBySearch/text/%D9%86%D9%88%D8%B1%D9%88%D8%B2` url is working as get request when im trying it – ρяσѕρєя K Feb 11 '16 at 13:32
  • 1
    @kianarahimi: Welcome Dear. – ρяσѕρєя K Feb 11 '16 at 13:34
  • can i have you skpe id :D – kiana rahimi Feb 11 '16 at 13:34