dongshi4589 2010-10-21 03: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-21 04: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条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘