我是 Android Studio 的新手。 在下面的代码中,我尝试将数据从 java 发送到后端服务器(在 PHP 中)。正在进行调用,但从服务器端返回 NULL,这是不应该发生的。所以我认为从 java 端发送的输入在 PHP 端没有被正确解释。你能告诉我代码有什么问题吗(PHP 代码完全正确,它不应该返回 NULL)。
HttpURLConnection httpURLConnection = null;
JSONObject Student_det = stu_det.getJSONObject(i);
String stu_GUID = Student_det.getString("StuGUID");
String visit_GUID = Student_det.getString("VisitGUID");
String value = "Rec="+(tableRow+1)+"&SchGUID="+schoolGUID.trim()+"&StuGUID="+stu_GUID.trim()+"&VisitGUID="+visit_GUID.trim()+"&role="+role;
URL url = new URL("http://52.66.25.82/api/download_student.php");
String enc_val = URLEncoder.encode(value,"UTF-8");
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("POST");
OutputStreamWriter wr = new OutputStreamWriter(httpURLConnection.getOutputStream());
wr.write( enc_val );
wr.flush();
InputStream responseStream = new BufferedInputStream(httpURLConnection.getInputStream());
BufferedReader responseStreamReader =
new BufferedReader(new InputStreamReader(responseStream));
// Read Server Response
String output = responseStreamReader.readLine();
最佳答案
关于java - 从 android 到 PHP 的 HTTP post 调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46906200/