首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从android到PHP的HTTP post调用?

从android到PHP的HTTP post调用?
EN

Stack Overflow用户
提问于 2017-10-24 16:58:53
回答 2查看 1.2K关注 0票数 0

我是Android Studio的新手。在下面的代码中,我尝试将数据从java发送到后端服务器(用PHP编写)。正在进行调用,但从服务器端返回NULL,这是不应该发生的。所以我认为从java端发送的输入在PHP端没有得到正确的解释。你能告诉我代码出了什么问题吗( PHP代码是完全正确的,它不应该返回NULL)。

代码语言:javascript
复制
          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();
EN

回答 2

Stack Overflow用户

发布于 2017-10-24 17:25:12

正如你所说的android新手,从最好的方式开始

尝试用volley库或RetroFit库实现,简单易用

volley example

RetroFit example

票数 1
EN

Stack Overflow用户

发布于 2017-10-24 17:46:42

要使安卓应用程序的REST完全调用Api,请使用Square.inc的Retrofit,这是在安卓应用程序中调用web服务的最快、最好的方法

查看这个简单的改装示例应用程序来调用Api's -

https://github.com/TheSeasApps/Easy-Retrofit

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46906200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档