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);
    }
4
  • In which language api is developed? Commented Feb 11, 2016 at 13:15
  • i think php . this site is public and i cant access to site code Commented Feb 11, 2016 at 13:16
  • either encode as @ρяσѕρєя-k suggested. alternatively you can try sending as POST instead of GET Commented Feb 11, 2016 at 13:28
  • Did you take a look here? Commented Feb 11, 2016 at 13:32

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

6 Comments

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 .
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);
@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
@kianarahimi: Welcome Dear.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.