开发者

How to write a java desktop app that can interact with my website's API?

It's a big question but I just need a push in the right direction.

I have a website being released soon. One of the services it provides is image hosting. I'm thinking about writing a desktop app in Java to help facilitate mass uploads as well as forcing me to use Java for real-world experience.

How does java send "requests" to an API? I'm using codeigniter for the website, and for those who are unfamiliar, the urls are broken down into 3 parts.

/controller/action/id So for example : http://google.com/users/addphoto/23 would access the "users" controller, which contains the function "addphoto" and $id would be set to the value "23".

I'm assuming I will need to get java to access an API using the above url structure, but how do I "do that"? How do I tell the application that accessing this url (ex. "user/authenticate") with x parameters will yield the information (ex "authentication token") it needs?

I know this question probably makes no sense but I'm lacking the basic ideas of how Java interacts with anything outside its own project folder. I can write the php stuff just fine, but I don't want to start until I know what java is capable of.

I did search around a bit before asking, but a lot of people are java developers st开发者_如何学运维ruggling with php, and I'm in the complete opposite position.


Apache HttpClient might be a good idea.


What you want to be able to do is read and write to URLs. Take a look at the official docs

http://download.oracle.com/javase/tutorial/networking/urls/readingWriting.html

The sample program should get you started. Once you understand how to open URLs, you'll be able to pass in parameters that will let you authenticate the java application with your php app.

Even more useful is this application which has the source code for the uploading portion of your needs

http://www.oop-reserch.com/mime_example_5.html

You'll still have to handle authentication on your own. You can have the php app pass back the session ID via xml or however you want, and add that to every request to authenticate the user.


This might be a good starting point for you:
http://download.oracle.com/javase/tutorial/networking/urls/index.html


Getting information is the easy part. Transforming the response, what is sent back to you from hitting the URL, to what you are looking for may be the hard part.

Their are two main ways to send data to a service, GET and POST. Using GET is just putting the information in the URL, an example would be "http://google.com/users/addphoto/23?MoreInfo=foo". Using POST means you are sending the information along with the URL. You will most likely use a combination of them to accomplish your goal.

I do not know what service or how codeigniter has setup their stuff, but once you figure that out you can use the following URL to help you get started.

http://www.exampledepot.com/egs/java.net/post.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜