Reputation: 246
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);
}
Upvotes: 2
Views: 639
Reputation: 132982
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;
Upvotes: 3