允许通过xml远程访问数据?

时间:2011-04-12 18:47:59

标签: xml database api

如果我想允许某人访问数据,以便他们可以将其放在他们的网站上,我可以让他们指向我的服务器上的脚本,该脚本通过url接收某些查询并且该脚本查询我的数据库,然后发送回数据以xml格式请求脚本的人?这将是一个非常基本的api设置不是吗?没有很多数据,也没有很多电话,所以不要担心它会减慢我的网站速度。我只是想知道这是否是创建api的正常/基本方式?

1 个答案:

答案 0 :(得分:1)

您所描述的基本上是web service

我建议您尝试使用RESTful API。归结起来:您在服务器上为您的客户提供某些URL。他们调用该URL并以某种格式(通常是XML或JSON)向他们发送信息,以便进一步处理。

示例:尝试访问此网站:

http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=stackoverflow

您将收到此回复:

{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://stackoverflow.com/","url":"http://stackoverflow.com/","visibleUrl":"stackoverflow.com","cacheUrl":"http://www.google.com/search?q\u003dcache:U1GC2GYOToIJ:stackoverflow.com","title":"\u003cb\u003eStack Overflow\u003c/b\u003e","titleNoFormatting":"Stack Overflow","content":"A language-independent collaboratively edited question and answer site for   programmers."},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://stackoverflow.com/users/login","url":"http://stackoverflow.com/users/login","visibleUrl":"stackoverflow.com","cacheUrl":"http://www.google.com/search?q\u003dcache:4nkh8ecRZGUJ:stackoverflow.com","title":"Log In - \u003cb\u003eStack Overflow\u003c/b\u003e","titleNoFormatting":"Log In - Stack Overflow","content":"\u003cb\u003estackoverflow\u003c/b\u003e.com ■ api/apps ■ careers ■ serverfault.com ■ superuser.com \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://blog.stackoverflow.com/","url":"http://blog.stackoverflow.com/","visibleUrl":"blog.stackoverflow.com","cacheUrl":"http://www.google.com/search?q\u003dcache:iqtvg9Ge1c0J:blog.stackoverflow.com","title":"Blog – Stack Exchange","titleNoFormatting":"Blog – Stack Exchange","content":"They seem to think that we only have 659000 visitors to \u003cb\u003estackoverflow\u003c/b\u003e.com \u003cb\u003e...\u003c/b\u003e"},{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://en.wikipedia.org/wiki/Stack_overflow","url":"http://en.wikipedia.org/wiki/Stack_overflow","visibleUrl":"en.wikipedia.org","cacheUrl":"http://www.google.com/search?q\u003dcache:mWu8b0BQAmwJ:en.wikipedia.org","title":"\u003cb\u003eStack overflow\u003c/b\u003e - Wikipedia, the free encyclopedia","titleNoFormatting":"Stack overflow - Wikipedia, the free encyclopedia","content":"In software, a \u003cb\u003estack overflow\u003c/b\u003e occurs when too much memory is used on the call   stack. The call stack contains a limited amount of memory, often determined at   \u003cb\u003e...\u003c/b\u003e"}],"cursor":{"pages":[{"start":"0","label":1},{"start":"4","label":2},{"start":"8","label":3},{"start":"12","label":4},{"start":"16","label":5},{"start":"20","label":6},{"start":"24","label":7},{"start":"28","label":8}],"estimatedResultCount":"1410000","currentPageIndex":0,"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den\u0026q\u003dstackoverflow"}}, "responseDetails": null, "responseStatus": 200}

当您搜索“Stackoverflow”时,这是Google的搜索结果。

相关问题