简体   繁体   中英

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. I'm using POST method and I can't figure it out why it doesn't work. 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. I want to transfer data to server exclusively with the POST method, not 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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