Home I am sending GET method to server but receiving POST method
Reply: 2

I am sending GET method to server but receiving POST method

Md . Sojib Ahmed
1#
Md . Sojib Ahmed Published in 2017-11-15 00:33:25Z

I am sending GET command to the server but in the Apache log I am getting POST method.

URL url = new URL("http://192.168.0.111/shakil/shakil.php/?data=shakil,123,123,123");
JSONObject postDataParams = new JSONObject();
postDataParams.put("name", "nazmul");
postDataParams.put("email", "hossainnazmul93@gmail.com");
Log.e("params",postDataParams.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(3000 /* milliseconds */);
conn.setConnectTimeout(3000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();

Although the method is GET. Can Any one suggest me what is the problem?

diegoveloper
2#
diegoveloper Reply to 2017-11-15 01:12:24Z

Comment this line:

conn.setDoOutput(true); 
EJP
3#
EJP Reply to 2017-11-15 06:26:36Z

I am sending GET method

No you aren't. This line:

conn.setDoOutput(true);

sets the request method to POST. You are also doing some output, which doesn't match with a GET request either. If you want a GET, remove the line above and the lines that do the output. Probably you should send the parameters encoded into the URL.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.474121 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO