Jump to content

Java - add-file


DarkFlare

Recommended Posts

Hi guys

Been 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

  • 1 year later...

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 regards

Darkflare

(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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...