Wednesday, May 05, 2010
Monday, January 25, 2010
HttpCommons and Ror
I finally got everything to work - in case this helps anyone else:
httpClient.getParams().setParameter("http.socket.timeout",
new Integer(90000)); // 90 second
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_0);
httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,
"UTF-8");
post = new HttpPost(new URI(url));
Charset chars = Charset.forName("UTF-8");
StringBody user_id = new StringBody("32432", chars);
MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartContent.addPart("media_entry[media]", new FileBody(file));
multipartContent.addPart("media_entry[user_id]", user_id);
post.setEntity(multipartContent);
HttpResponse response = httpClient.execute(post);
response.getEntity().getContent().close();
does the trick.
The important part is the forcing of the HTTP/1.0 protocol, since most rails web servers don't support chunked-encoding.
Posted by anthonyj at 6:18 AM 0 comments
Saturday, January 23, 2010
Android and RoR Rest Services
In case this helps anyone else:
When you are doing multipart uploads from Android to Rails, you need to make sure that you tell the MultipartEntry to be Browser compatible:
MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);and now I'll get back to our new project. More to come when we release an alpha version.
multipartContent.addPart("media_entry[media]", new FileBody(file));
multipartContent.addPart("media_entry[user_id]", sb1);
Posted by anthonyj at 9:34 AM 0 comments
Subscribe to:
Posts (Atom)