Hi players,
I'm trying to post a form using the WS library. But so far, I'm unable
to make it works.
This code:
String formParams = WS.encode("access_token=" + getAccessToken() +
"&message=Hello World!");
WS.url("
https://graph.facebook.com/me/
feed").body(formParams).mimeType("multipart/form-data").post();
Gives me the following error:
RuntimeException occured : java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
play.exceptions.JavaExecutionException: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:285)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.post(WSUrlFetch.java:58)
at controllers.Application.writeReview(Application.java:63)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:408)
at
play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:403)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:176)
... 1 more
Caused by: java.lang.RuntimeException:
java.lang.IllegalStateException: Already connected
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.prepare(WSUrlFetch.java:126)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.post(WSUrlFetch.java:56)
... 5 more
Caused by: java.lang.IllegalStateException: Already connected
at
sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:
2371)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:
296)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.checkFileBody(WSUrlFetch.java:170)
at play.libs.ws.WSUrlFetch
$WSUrlfetchRequest.prepare(WSUrlFetch.java:113)
... 6 more
However, it works as expected using the Apache HttpClient library:
List<NameValuePair> formParams = new ArrayList<NameValuePair>();
formParams.add(new BasicNameValuePair("access_token",
getAccessToken()));
formParams.add(new BasicNameValuePair("message", "Hello World!"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams,
"UTF-8");
HttpPost post = new HttpPost("
https://graph.facebook.com/me/feed");
post.setHeader("Content-Type", "multipart/form-data");
post.setEntity(entity);
HttpClient client = new DefaultHttpClient();
org.apache.http.HttpResponse resp = (org.apache.http.HttpResponse)
client.execute(post);
Did I miss something about the WS library and the post method? Is
there a bug?
I'm using Play! 1.1.
Thank you in advance for your help.
Eric