Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android/PHP-JSONParser无法将网页内容获取为JsonObject_Php_Android_Json_Httprequest - Fatal编程技术网

Android/PHP-JSONParser无法将网页内容获取为JsonObject

Android/PHP-JSONParser无法将网页内容获取为JsonObject,php,android,json,httprequest,Php,Android,Json,Httprequest,关于JSONParser有很多问题,但似乎什么都不起作用。 因此,我在服务器上有一个php脚本 这个php脚本从数据库中获取一些数据,并用这些数据生成一个Json 我验证了这个Json,它是正确的 在android中,我有一个JSONParser,它连接到php脚本url并获取网页内容 问题是页面内容不正确,我不知道为什么 我还使用了OkHttp和URLConnection,它提供了相同的输出 我还使用了改装,这也不起作用,我对stackoverflow有一个问题 这可能与JavaScript有

关于JSONParser有很多问题,但似乎什么都不起作用。 因此,我在服务器上有一个php脚本

这个php脚本从数据库中获取一些数据,并用这些数据生成一个Json

我验证了这个Json,它是正确的

在android中,我有一个JSONParser,它连接到php脚本url并获取网页内容

问题是页面内容不正确,我不知道为什么

我还使用了OkHttpURLConnection,它提供了相同的输出

我还使用了改装,这也不起作用,我对stackoverflow有一个问题

这可能与JavaScript有关

这是脚本链接:

    {
         "success": 0,
         "message": "RequiredFieldMissing"
    }
<?php 
// array for JSON response
$response = array();

// check for required fields
 if (isset($_POST['param1']) && isset($_POST['param2'])){

// include db connect class
require_once __DIR__ . '/connect_to_db.php';

// connecting to db
$db = new DB_CONNECT();

 $param1 = $_POST['param1'];
 $param2 = $_POST['param2'];

 // get data
$result = mysql_query("SELECT param1 FROM tableName WHERE param2 = '$param2'") or die(mysql_error());

    if (mysql_num_rows($result)>0) {

        $row = mysql_fetch_array($result);
        if ($row["param1"] == $param1){
            // success
                $response["success"] = 1;
                $response["message"] = "Correct";
        } else {
                // no success
            $response["success"] = 0;
            $response["message"] = "Incorrect";
        }

    } else {
    // no data found
    $response["success"] = 0;
    $response["message"] = "NoData";

    }
    // echo JSON
        echo json_encode($response);
 } else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "RequiredFieldMissing";

    // echoing JSON
    echo json_encode($response);
}
?>
    public class JSONParser {

    static InputStream is = null;

    static JSONObject jObj = null;

    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET mehtod
    public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if (method == "POST") {
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            } else if (method == "GET") {
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }

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

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}
apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.0"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.myApp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.google.code.gson:gson:2.4'
    compile 'org.glassfish:javax.annotation:10.0-b28'
}
public class SomeTask extends AsyncTask<Void, Void, Boolean> {

    private final String param1;

    private final String param2;

    private String message;

    UserLoginTask(String param1, String param2) {
        this.param1 = param1;
        this.param2 = param2;
        message = StringUtils.EMPTY;
    }

    @Override
    protected Boolean doInBackground(Void... param) {

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("param1", "param1Value"));
        params.add(new BasicNameValuePair("param2", "param2Value"));

        // Creating JSON Parser object
        JSONParser jsonParser = new JSONParser();

        // getting JSON Object
        // Note that create product url accepts POST method
        JSONObject json = jsonParser.makeHttpRequest(my_url, "GET", params);

        if (json == null) {
            return Boolean.FALSE;
        } else {
            Log.d("JSON: ", json.toString());
        }

        try {
            if (json.getInt(TAG_SUCCESS) == 1) {
                return Boolean.TRUE;
            } else {
                message = json.getString(TAG_MESSAGE);
                return Boolean.FALSE;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return Boolean.FALSE;
    }

    @Override
    protected void onPostExecute(final Boolean success) {
        mAuthTask = null;
        showProgress(false);

        if (success) {
            finish();
            startActivity(new Intent(ThisActivity.this, NextActivity.class));
        } else {
            if ("Incorrect".equals(message)) {
                mPasswordView.setError(getString(R.string.error_incorrect_credentials));
                mPasswordView.requestFocus();
            } else if ("NoData".equals(message)) {
                mPasswordView.setError(getString(R.string.error_no_account_found));
                mPasswordView.requestFocus();
            } else {
                mPasswordView.setError(getString(R.string.unknown_error));
                mPasswordView.requestFocus();
            }
        }
    }
}

这是php脚本生成的json:

    {
         "success": 0,
         "message": "RequiredFieldMissing"
    }
<?php 
// array for JSON response
$response = array();

// check for required fields
 if (isset($_POST['param1']) && isset($_POST['param2'])){

// include db connect class
require_once __DIR__ . '/connect_to_db.php';

// connecting to db
$db = new DB_CONNECT();

 $param1 = $_POST['param1'];
 $param2 = $_POST['param2'];

 // get data
$result = mysql_query("SELECT param1 FROM tableName WHERE param2 = '$param2'") or die(mysql_error());

    if (mysql_num_rows($result)>0) {

        $row = mysql_fetch_array($result);
        if ($row["param1"] == $param1){
            // success
                $response["success"] = 1;
                $response["message"] = "Correct";
        } else {
                // no success
            $response["success"] = 0;
            $response["message"] = "Incorrect";
        }

    } else {
    // no data found
    $response["success"] = 0;
    $response["message"] = "NoData";

    }
    // echo JSON
        echo json_encode($response);
 } else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "RequiredFieldMissing";

    // echoing JSON
    echo json_encode($response);
}
?>
    public class JSONParser {

    static InputStream is = null;

    static JSONObject jObj = null;

    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET mehtod
    public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if (method == "POST") {
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            } else if (method == "GET") {
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }

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

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}
apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.0"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.myApp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.google.code.gson:gson:2.4'
    compile 'org.glassfish:javax.annotation:10.0-b28'
}
public class SomeTask extends AsyncTask<Void, Void, Boolean> {

    private final String param1;

    private final String param2;

    private String message;

    UserLoginTask(String param1, String param2) {
        this.param1 = param1;
        this.param2 = param2;
        message = StringUtils.EMPTY;
    }

    @Override
    protected Boolean doInBackground(Void... param) {

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("param1", "param1Value"));
        params.add(new BasicNameValuePair("param2", "param2Value"));

        // Creating JSON Parser object
        JSONParser jsonParser = new JSONParser();

        // getting JSON Object
        // Note that create product url accepts POST method
        JSONObject json = jsonParser.makeHttpRequest(my_url, "GET", params);

        if (json == null) {
            return Boolean.FALSE;
        } else {
            Log.d("JSON: ", json.toString());
        }

        try {
            if (json.getInt(TAG_SUCCESS) == 1) {
                return Boolean.TRUE;
            } else {
                message = json.getString(TAG_MESSAGE);
                return Boolean.FALSE;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return Boolean.FALSE;
    }

    @Override
    protected void onPostExecute(final Boolean success) {
        mAuthTask = null;
        showProgress(false);

        if (success) {
            finish();
            startActivity(new Intent(ThisActivity.this, NextActivity.class));
        } else {
            if ("Incorrect".equals(message)) {
                mPasswordView.setError(getString(R.string.error_incorrect_credentials));
                mPasswordView.requestFocus();
            } else if ("NoData".equals(message)) {
                mPasswordView.setError(getString(R.string.error_no_account_found));
                mPasswordView.requestFocus();
            } else {
                mPasswordView.setError(getString(R.string.unknown_error));
                mPasswordView.requestFocus();
            }
        }
    }
}
这是PHP脚本:

    {
         "success": 0,
         "message": "RequiredFieldMissing"
    }
<?php 
// array for JSON response
$response = array();

// check for required fields
 if (isset($_POST['param1']) && isset($_POST['param2'])){

// include db connect class
require_once __DIR__ . '/connect_to_db.php';

// connecting to db
$db = new DB_CONNECT();

 $param1 = $_POST['param1'];
 $param2 = $_POST['param2'];

 // get data
$result = mysql_query("SELECT param1 FROM tableName WHERE param2 = '$param2'") or die(mysql_error());

    if (mysql_num_rows($result)>0) {

        $row = mysql_fetch_array($result);
        if ($row["param1"] == $param1){
            // success
                $response["success"] = 1;
                $response["message"] = "Correct";
        } else {
                // no success
            $response["success"] = 0;
            $response["message"] = "Incorrect";
        }

    } else {
    // no data found
    $response["success"] = 0;
    $response["message"] = "NoData";

    }
    // echo JSON
        echo json_encode($response);
 } else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "RequiredFieldMissing";

    // echoing JSON
    echo json_encode($response);
}
?>
    public class JSONParser {

    static InputStream is = null;

    static JSONObject jObj = null;

    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET mehtod
    public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if (method == "POST") {
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            } else if (method == "GET") {
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }

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

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}
apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.0"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.myApp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.google.code.gson:gson:2.4'
    compile 'org.glassfish:javax.annotation:10.0-b28'
}
public class SomeTask extends AsyncTask<Void, Void, Boolean> {

    private final String param1;

    private final String param2;

    private String message;

    UserLoginTask(String param1, String param2) {
        this.param1 = param1;
        this.param2 = param2;
        message = StringUtils.EMPTY;
    }

    @Override
    protected Boolean doInBackground(Void... param) {

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("param1", "param1Value"));
        params.add(new BasicNameValuePair("param2", "param2Value"));

        // Creating JSON Parser object
        JSONParser jsonParser = new JSONParser();

        // getting JSON Object
        // Note that create product url accepts POST method
        JSONObject json = jsonParser.makeHttpRequest(my_url, "GET", params);

        if (json == null) {
            return Boolean.FALSE;
        } else {
            Log.d("JSON: ", json.toString());
        }

        try {
            if (json.getInt(TAG_SUCCESS) == 1) {
                return Boolean.TRUE;
            } else {
                message = json.getString(TAG_MESSAGE);
                return Boolean.FALSE;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return Boolean.FALSE;
    }

    @Override
    protected void onPostExecute(final Boolean success) {
        mAuthTask = null;
        showProgress(false);

        if (success) {
            finish();
            startActivity(new Intent(ThisActivity.this, NextActivity.class));
        } else {
            if ("Incorrect".equals(message)) {
                mPasswordView.setError(getString(R.string.error_incorrect_credentials));
                mPasswordView.requestFocus();
            } else if ("NoData".equals(message)) {
                mPasswordView.setError(getString(R.string.error_no_account_found));
                mPasswordView.requestFocus();
            } else {
                mPasswordView.setError(getString(R.string.unknown_error));
                mPasswordView.requestFocus();
            }
        }
    }
}
这是异步任务类:

    {
         "success": 0,
         "message": "RequiredFieldMissing"
    }
<?php 
// array for JSON response
$response = array();

// check for required fields
 if (isset($_POST['param1']) && isset($_POST['param2'])){

// include db connect class
require_once __DIR__ . '/connect_to_db.php';

// connecting to db
$db = new DB_CONNECT();

 $param1 = $_POST['param1'];
 $param2 = $_POST['param2'];

 // get data
$result = mysql_query("SELECT param1 FROM tableName WHERE param2 = '$param2'") or die(mysql_error());

    if (mysql_num_rows($result)>0) {

        $row = mysql_fetch_array($result);
        if ($row["param1"] == $param1){
            // success
                $response["success"] = 1;
                $response["message"] = "Correct";
        } else {
                // no success
            $response["success"] = 0;
            $response["message"] = "Incorrect";
        }

    } else {
    // no data found
    $response["success"] = 0;
    $response["message"] = "NoData";

    }
    // echo JSON
        echo json_encode($response);
 } else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "RequiredFieldMissing";

    // echoing JSON
    echo json_encode($response);
}
?>
    public class JSONParser {

    static InputStream is = null;

    static JSONObject jObj = null;

    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET mehtod
    public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if (method == "POST") {
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            } else if (method == "GET") {
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }

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

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}
apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.0"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.myApp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.google.code.gson:gson:2.4'
    compile 'org.glassfish:javax.annotation:10.0-b28'
}
public class SomeTask extends AsyncTask<Void, Void, Boolean> {

    private final String param1;

    private final String param2;

    private String message;

    UserLoginTask(String param1, String param2) {
        this.param1 = param1;
        this.param2 = param2;
        message = StringUtils.EMPTY;
    }

    @Override
    protected Boolean doInBackground(Void... param) {

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("param1", "param1Value"));
        params.add(new BasicNameValuePair("param2", "param2Value"));

        // Creating JSON Parser object
        JSONParser jsonParser = new JSONParser();

        // getting JSON Object
        // Note that create product url accepts POST method
        JSONObject json = jsonParser.makeHttpRequest(my_url, "GET", params);

        if (json == null) {
            return Boolean.FALSE;
        } else {
            Log.d("JSON: ", json.toString());
        }

        try {
            if (json.getInt(TAG_SUCCESS) == 1) {
                return Boolean.TRUE;
            } else {
                message = json.getString(TAG_MESSAGE);
                return Boolean.FALSE;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return Boolean.FALSE;
    }

    @Override
    protected void onPostExecute(final Boolean success) {
        mAuthTask = null;
        showProgress(false);

        if (success) {
            finish();
            startActivity(new Intent(ThisActivity.this, NextActivity.class));
        } else {
            if ("Incorrect".equals(message)) {
                mPasswordView.setError(getString(R.string.error_incorrect_credentials));
                mPasswordView.requestFocus();
            } else if ("NoData".equals(message)) {
                mPasswordView.setError(getString(R.string.error_no_account_found));
                mPasswordView.requestFocus();
            } else {
                mPasswordView.setError(getString(R.string.unknown_error));
                mPasswordView.requestFocus();
            }
        }
    }
}
公共类SomeTask扩展了AsyncTask{
私有最终字符串param1;
私有最终字符串param2;
私有字符串消息;
UserLoginTask(字符串参数1,字符串参数2){
this.param1=param1;
this.param2=param2;
message=StringUtils.EMPTY;
}
@凌驾
受保护的布尔doInBackground(Void…param){
//建筑参数
List params=new ArrayList();
添加(新的BasicNameValuePair(“param1”、“param1Value”);
添加(新的BasicNameValuePair(“param2”、“param2Value”);
//创建JSON解析器对象
JSONParser JSONParser=新的JSONParser();
//获取JSON对象
//请注意,创建产品url接受POST方法
JSONObject json=jsonParser.makeHttpRequest(我的url,“GET”,参数);
if(json==null){
返回Boolean.FALSE;
}否则{
Log.d(“JSON:,JSON.toString());
}
试一试{
if(json.getInt(TAG_SUCCESS)==1){
返回Boolean.TRUE;
}否则{
message=json.getString(TAG_message);
返回Boolean.FALSE;
}
}捕获(JSONException e){
e、 printStackTrace();
}
返回Boolean.FALSE;
}
@凌驾
受保护的void onPostExecute(最终布尔值成功){
mAuthTask=null;
显示进度(假);
如果(成功){
完成();
startActivity(新意图(ThisActivity.this,NextActivity.class));
}否则{
如果(“不正确”。等于(消息)){
mPasswordView.setError(getString(R.string.error\u凭证不正确));
mPasswordView.requestFocus();
}else if(“NoData”.equals(message)){
mPasswordView.setError(getString(R.string.error\u找不到帐户));
mPasswordView.requestFocus();
}否则{
mPasswordView.setError(getString(R.string.unknown_error));
mPasswordView.requestFocus();
}
}
}
}
这是我得到的输出:


函数toNumbers(d){var e=[];d.replace(/(..)/g,函数(d){e.push(parseInt(d,16));将e}函数返回hex(){for(var d=[],d=1==参数。长度和参数[0]。构造函数==数组?参数[0]:参数,e=“”,f=0;fd[f]?“0:”)+d[f]。toString(16);返回e.toLowerCase()}var a=toNumbers(“F655BA9D0968C635B4B=Tonb4b”)(“98344C2EE86C3994890592585B49F80”),c=t数字(“6edf9232af73be55d6cc499e851409b9”);document.cookie=“u test=“+toHex(slowAES.decrypt(c,2,a,b))+”;expires=Thu,37年12月31日23:55:55 GMT;path=/“document.cookie=”referer=“+escape(document.referer);location.href=”http://mobilehealth.byethost11.com/aScript.php?param1=param1Value¶m2=param2Value&ckattempt=1";此站点需要Javascript才能工作,请在浏览器中启用Javascript或使用支持Javascript的浏览器
最好使用UTF-8而不是iso-8859-1。我想这个问题可能在你正在使用的字符集中


并确保在编写字符串时添加了一些不需要的字符(没有意外插入特殊字符)。

我不知道问题出在哪里,但我在xampp和其他主机上进行了尝试,现在它可以工作了。 我认为问题在于主机以某种方式使用javascript进行响应。
以上所有代码都是正确的。

尝试使用xampp在localhost上运行此请求,我认为问题出在您的免费web托管网站上。它对我的一位朋友有效,但我不知道为什么它对我无效。我将尝试使用另一个主机或xamppi使用postman向您的php文件发送请求,我得到了相同的结果。尝试发送一个无cookie的请求。无论是否使用cookie,它都会给出相同的结果从php端使用什么字符集。这个家伙正面临同样的iso-8859-1问题,正确地说,这个家伙从他的php脚本中捕获错误,并且php标记之间有空格