Connecting webservice android

0

Hello, guys, I'm developing an app in the Android Studio IDE and I'm having trouble connecting to my webservice. I'm getting the error: D / response: {"success": "false", "message": "The JSONObject text must begin with '{' at character 1 of location = 25"}, follow the code. Does anyone know how I can solve this problem? Thank you in advance.

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://MY_HOST");
        httpPost.setHeader("Content-Type","application/json;charset=UTF-8");
        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
        pairs.add(new BasicNameValuePair("location","25"));

        try {
            httpPost.setEntity(new UrlEncodedFormEntity(pairs, "UTF-8"));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            serverData = EntityUtils.toString(httpEntity);
            Log.d("response", serverData);

        } catch (ClientProtocolException e) {
            e.printStackTrace();

        } catch (IOException e) {
            e.printStackTrace();

        }
    
asked by anonymous 30.12.2015 / 23:11

1 answer

0

Your PHP file is not generating JSON properly, this may be the cause. Do the test in the browser and see if it is generating the JSON, if it is JSONArray, starting with [ or if it is JSONObject, starting with {. The log that you are capturing is the message returned in the connection, the same one written in the web file using echo, if it is in PHP.

    
31.12.2015 / 00:45