简体   繁体   English

我的PHP文件没有使用POST方法从我的Android应用程序接收数据

[英]My PHP file doesn't receive data from my android app using POST method

I have a problem with php file when it should receive some data form my android app. 当它应该从我的Android应用程序接收一些数据时,php文件出现问题。 I'm using POST method and I can't figure it out why it doesn't work. 我正在使用POST方法,无法弄清楚为什么它不起作用。 I've tried searching for answers but everything I tried, it doesn' work. 我已经尝试过寻找答案,但是我尝试过的所有方法都行不通。 First, I used URLConnection class for connection with server, and after that, I tried with HttpURLConnection, but still doesn't work. 首先,我使用URLConnection类与服务器进行连接,然后,我尝试使用HttpURLConnection,但仍然无法正常工作。 I want to transfer data to server exclusively with the POST method, not GET. 我想仅通过POST方法而不是GET将数据传输到服务器。 Could anyone explane me what I'm doing wrong, or did I forget something to add or configure? 有人能解释我做错了什么吗,还是忘记了要添加或配置的内容?

Did you try something like this : URL url = new URL("your_url_here"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setDoOutput(true); connection.setConnectTimeout(10000); connection.setReadTimeout(10000); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Accept", "application/json"); connection.connect(); byte[] output = "your data to send here".getBytes("UTF-8"); OutputStream os = connection.getOutputStream(); os.write(output); os.flush(); os.close(); 您是否尝试过类似的方法: URL url = new URL("your_url_here"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setDoOutput(true); connection.setConnectTimeout(10000); connection.setReadTimeout(10000); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Accept", "application/json"); connection.connect(); byte[] output = "your data to send here".getBytes("UTF-8"); OutputStream os = connection.getOutputStream(); os.write(output); os.flush(); os.close(); URL url = new URL("your_url_here"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setDoOutput(true); connection.setConnectTimeout(10000); connection.setReadTimeout(10000); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Accept", "application/json"); connection.connect(); byte[] output = "your data to send here".getBytes("UTF-8"); OutputStream os = connection.getOutputStream(); os.write(output); os.flush(); os.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM