fredsa / playn

Cross platform game library for N≥4 platforms
0 stars 1 forks source link

JavaNet not doing POST correctly #107

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use PlayN.net().post(...)
2. Do debug or println in the server side (eg. as servlet)
3. The request parameters are not being found eg. 
request.getParameter("myParam") will return null

What is the expected output? What do you see instead?
requst.getParameter("myParam") should return what ever that is pass as data 
parameter in post(...) method in myParam=a&myParam2=b format

What version of the product are you using? On what operating system?
Doesn't matter

Please provide any additional information below.

Following patch seems to work for me :-

From dd74c30660e8a1e26ce75f25e3885cd7ae419217 Mon Sep 17 00:00:00 2001
From: tmjee <tmjee@tmjee-laptop.(none)>
Date: Sun, 18 Dec 2011 17:29:39 +1100
Subject: [PATCH] Fix JavaNet#post not doing HTTP post

---
 java/src/playn/java/JavaNet.java |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/java/src/playn/java/JavaNet.java b/java/src/playn/java/JavaNet.java
index c6bf50d..741d7c5 100644
--- a/java/src/playn/java/JavaNet.java
+++ b/java/src/playn/java/JavaNet.java
@@ -58,7 +58,8 @@ public class JavaNet implements Net {
       conn.setDoOutput(true);
       conn.setDoInput(true);
       conn.setAllowUserInteraction(false);
-      conn.setRequestProperty("Content-type", "text/xml; charset=UTF-8");
+      conn.setUseCaches(false);
+      conn.setRequestProperty("Content-Type", 
"application/x-www-form-urlencoded");

       conn.connect();
       conn.getOutputStream().write(data.getBytes("UTF-8"));
-- 
1.7.5.4

If someone can take a look that'd be great.

Cheers
Toby

Original issue reported on code.google.com by tmj...@gmail.com on 18 Dec 2011 at 6:42

GoogleCodeExporter commented 9 years ago
Now that i've think of it maybe this is not a bug after all, we could get 
around this by using 

request.getReader() or request.getInputStream() 

and manually parse the request body

Just wondering as well, is there are reason for not allowing the post interface 
to set the content type?

Original comment by tmj...@gmail.com on 18 Dec 2011 at 10:40