0

我将带有 json 对象的 post 请求发送到服务器中的 php,但 php 一直告诉 $_POST 是空的。

这是好的http代码

    public String postConection(JSONObject pJson, String pUrl) throws IOException {
    final MediaType JSON
            = MediaType.parse("application/json; charset=utf-8");

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);

    String dirArchivo = "http://10.0.2.2/SoulStoreProject/"+pUrl;

    OkHttpClient client = new OkHttpClient();

    RequestBody body = RequestBody.create(JSON, pJson.toString());
    Request request = new Request.Builder()
            .url(dirArchivo)
            .post(body)
            .build();
    Response response = client.newCall(request).execute();
    return response.body().string();
}

这是php代码

$nick = $_POST['nick'];
$password = $_POST['password']; 

$query = "
    INSERT INTO 
        players(nick, password) 
        VALUES($nick,$password)
    ";


$DB->Execute($query);
4

1 回答 1

2
于 2016-04-12T21:22:05.873 回答