I have following code where I am calling an API which is a PHP built. The code returns json stated as below which I am collecting in a stringBuilder object. Problem is its working on some carriers and on few devices with other carriers / wifi connection its throwing JSONException end of input at character 0 exception, i know this comes when input string is empty, it means stringBuilder object is empty. Problem is i don't have access to the devices on which its throwing these errors.
I am not getting on some device why following code returns empty string and on some its working fine, user has tested on 3G as well as wifi these devices are in other country on different carriers.
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost(ServiceUrls.base_url + ServiceUrls.get_profile_url);
JSONObject object = new JSONObject();
object.put("username", params[0]);
StringEntity input = new StringEntity(object.toString());
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
String output;
StringBuilder stringBuilder = new StringBuilder();
while ((output = br.readLine()) != null) {
stringBuilder.append(output);
}
If it was for all API call then it was logical but doest happen for other API call, this API call returns bigger size JSON string as follows in stringbuilder
{
"status":1, "parking":{
"name":"ghgjjghghg", "cost":3, "ownerId":29, "address":"xyz pqr", "slots":4, "image":"d4bc95c1dd031685746f2c3570788acf.jpg", "details":"gjhjghjgg", "amenities":"gjhg", "id":70, "lon":73.7898023, "lat":19.9974533, "type":0, "available":1 }, "rating":0, "ratingCount":0, "owner":{
"id":29, "username":"vd@gmail.com", "password":"", "fullname":"vi hdjh", "phone":"23434fddf", "ccNum":null, "ccType":null, "type":1, "authType":1, "image":"582e3a77d76ae3203cfd6d6a346da429.jpg", "dni":"abc123", "account":"ABCBANK" } }
I have no clue whats happening , please help. Any input will be appreciated.