Third party multipart request in playframework

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2012-09-09T21:34:04Z Indexed on 2012/09/09 21:38 UTC
Read the original article Hit count: 244

I'm making an application to post photos to yfrog and twitpic and I am having a little trouble figuring out how to set the parameters. Here is my code:

public static Result index() {
    HttpClient httpclient = new DefaultHttpClient();
    WSRequestHolder holder = WS.url("http://api.twitpic.com/2/upload.json");        
    holder.setHeader("Authorization", "");

    return async(holder.post("").map(new Function<WS.Response, Result>() {
        public Result apply(WS.Response response) { 
            return ok(response.getBody());
        }
    }));     
}

Now, I don't expect this to actually get an ok response from the server, as I am just testing the responses that I get back from the server, and that is one that says I need to provide the api key. I figured as much, but I'm not sure of the syntax for providing that parameter, as I need to also give the name of the file and the file. I tried setting holder.post("key=somekey"), with the hope that I would get a different error message (like the key you provided is invalid) but I just get the same error. I'm assuming that I probably need to send it in the for of a multipart request, but I am not very experienced with this kind of request and can't find any play documentation on how to create a multipart request, other than in an html form. Any suggestions and help will be much appreciated. And fyi, I do know that there are yfrog and twitpic java classes to handle this kind of stuff, but I want to do it myself, more so for learning how to do this kind of stuff. Thanks in advance!

© Stack Overflow or respective owner

Related posts about java

Related posts about playframework