[英]play framework send file in HTTP request
I'm working on a play framework 2 application and I would like to call a WebService and send a file ( an image ). 我正在使用play framework 2应用程序,我想调用WebService并发送文件(图像)。 I found the WS class but I cannot find how to send a file using it. 我找到了WS类,但找不到如何使用它发送文件。 What I found is this : 我发现的是:
WS.url("http://localhost:9001/post").post("content")
But I did not managed to send a file using a POST request. 但是我没有设法通过POST请求发送文件。
Can someone tell me how to do it ? 有人可以告诉我该怎么做吗?
Thanks. 谢谢。
CC 抄送
With Play > 2.0 this should do the trick: 在Play> 2.0下,这应该可以解决问题:
File file = new File("yourPath");
WS.url("/post/url").post(file);
Being able to add a parameter identifying your file the request should be send using multipart/form-data. 能够添加用于标识文件的参数,应使用multipart / form-data发送请求。 This Post shows how to do it with Play! 这篇文章展示了如何使用Play进行操作! - https://stackoverflow.com/a/18723326/2788883 -https://stackoverflow.com/a/18723326/2788883
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.