dongshi4589 2010-10-20 19:59
浏览 136
已采纳

如何编写可与我网站的API交互的Java桌面应用程序?

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 struggling with php, and I'm in the complete opposite position.

  • 写回答

4条回答 默认 最新

  • doujun5009 2010-10-20 20:08
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部