dongshi4589
2010-10-21 03:59
浏览 99
已采纳

如何编写可与我网站的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.

图片转代码服务由CSDN问答提供 功能建议

这是一个很大的问题,但我只需要朝着正确的方向努力。

我的网站即将发布。 它提供的服务之一是图像托管。 我正在考虑用Java编写一个桌面应用程序,以帮助实现大量上传,并迫使我使用Java来获得真实的体验。

java如何将“请求”发送给 API? 我正在为网站使用codeigniter,对于那些不熟悉的人,网址分为3个部分。
/ controller / action / id 例如: http://google.com/users/addphoto/23 将访问“用户”控制器,其中包含“addphoto”功能,$ id将设置为值“23”。

我假设我需要让java使用上面的url结构访问API,但我该如何“做到”? 如何通过x参数告诉应用程序访问此URL(例如“user / authenticate”)将产生所需的信息(例如“身份验证令牌”)?

我知道这个 问题可能毫无意义,但我缺乏Java如何与其自己的项目文件夹之外的任何东西进行交互的基本思想。 我可以编写php的东西就好了,但我不想开始,直到我知道java的功能。

我在询问之前做了一些搜索,但很多 人们是java开发人员在与PHP斗争,我处于完全相反的位置。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 打赏 评论
  • dongmozhui3805 2010-10-21 04:04

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

    点赞 打赏 评论
  • douxian1895 2010-10-21 04:15

    Apache HttpClient might be a good idea.

    点赞 打赏 评论
  • douqiao8032 2010-10-21 04:22

    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

    点赞 打赏 评论

相关推荐 更多相似问题