我是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();发布于 2017-10-24 17:25:12
发布于 2017-10-24 17:46:42
要使安卓应用程序的REST完全调用Api,请使用Square.inc的Retrofit,这是在安卓应用程序中调用web服务的最快、最好的方法
查看这个简单的改装示例应用程序来调用Api's -
https://stackoverflow.com/questions/46906200
复制相似问题