得到响应200但没有从android接收数据到php

时间:2016-03-21 15:13:23

标签: php android json post httpurlconnection

我已经这样做了2天了,我得到的回复是200但是当我试着查看我的php时,我的帖子代码没有来自android的数据,这是我在android中的代码:

    URL url = new URL("http:/sample.com/url.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");

String urlParameters = "uid=123";
conn.setRequestMethod("POST");
conn.setRequestProperty("USER-AGENT", "Mozilla/5.0");
conn.setRequestProperty("ACCEPT-LANGUAGE", "en-US,en;0.5");

conn.setDoOutput(true);

OutputStream dStream = conn.getOutputStream();

dStream.write(urlParameters.getBytes());
dStream.flush();
dStream.close();

int responseCode = conn.getResponseCode();
String output = "Request URL" + url;
output += System.getProperty("line.separator") + "Request Parameters " + urlParameters;
output += System.getProperty("line.separator") + "Response Code " + responseCode;

BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
StringBuilder responseOutput = new StringBuilder();

while((line = br.readLine()) != null){
    responseOutput.append(line);

}
br.close();

output += System.getProperty("line.separator") + responseOutput.toString();

System.out.println(output);

这只是我的PHP代码:

$get = json_decode(stripslashes($_POST['uid']));

var_dump($get);
var_dump($_POST);
var_dump($_GET);

我收到了响应代码200,但我的php文件中没有收到任何内容。请帮忙,我是一个新手android dev :(

0 个答案:

没有答案