DarkFlare Posted March 1, 2009 Report Share Posted March 1, 2009 Hi guysBeen reading this section of the forum for a couple of days now and tinkering around in java. I am trying to create a http post in java to send a torrent to the webgui, however im not getting very far. Its actually for the android platform, but android uses quite a few of the apache http methods.Here's what ive got so far: DefaultHttpClient client = new DefaultHttpClient();client.getCredentialsProvider().setCredentials(new AuthScope("192.168.1.128",8080), new UsernamePasswordCredentials(username, password));HttpPost htpost = new HttpPost("http://192.168.1.128:8080/gui/?action=add-file");File torrentFile = new File(new URI("file:///sdcard/download/dark.torrent"));//BasicHttpEntity postEntity = new BasicHttpEntity();//postEntity.setContent(new FileInputStream(torrentFile) );//postEntity.setContentEncoding("multipart/form-data");//postEntity.setContentLength(torrentFile.length());//postEntity.setContentType("multipart/form-data");//htpost.setEntity(postEntity);HttpResponse response = client.execute(htpost); HttpEntity entity = response.getEntity();Ive commented part of it out because it gave me a ClientProtocolError. But using this code without the postentity i manage to get a return document containing "{"build":14485,"error": "Error"}" which is comforting to know that its connecting.Does anyone have any advice or experiance in this area? i feel like i should be editing a header or something in place of using the postEntity.Some help would be greatly appreciated.DarkFlare Link to comment Share on other sites More sharing options...
cday119 Posted January 23, 2011 Report Share Posted January 23, 2011 Hey man,I'm about to embark on an android app similar to this, did you get this figured out? Link to comment Share on other sites More sharing options...
DarkFlare Posted January 23, 2011 Author Report Share Posted January 23, 2011 Hi cday119,To be honest I would say stop your project. There is already a solution on android thats free and open source (not my app either.. =() its called transdroid and you can find the source here:http://code.google.com/p/transdroid/source/browse/As for how I managed to send the requred data I used the apaches commons library in my android project so I could use the multipart entity. Basically it doesnt come as standard with android so you need to add it yourself.Sorry I cant be much more help. Over all though I'd say unless your doing this project for fun, best to stop now.Kind regardsDarkflare(ps if you really want to continue this process look at transdroid, or reply and I can send you some code) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.