我有一个服务器应用程序写在ASP。NET在Windows上提供web服务。

如何在Linux中使用cURL调用web服务?

HTTP GET请求的最大长度是多少?

如果服务器接收到超过这个长度的GET请求,是否定义了服务器可以/应该返回的响应错误?

这是在web服务API的上下文中,尽管浏览器的限制也很有趣。

我在寻找关于如何使用Android调用标准SOAP/WSDL web服务的好信息时遇到了很多麻烦。我所能找到的只是一些非常复杂的文档和对“kSoap2”的引用,以及一些关于用SAX手动解析它的内容。好吧,这很好,但现在是2008年,所以我认为应该有一些调用标准web服务的好库。

web服务基本上就是在NetBeans中创建的。我希望有IDE支持来生成管道类。我只是需要最简单/最优雅的方法来从基于android的电话联系基于WSDL的web服务。

当用户访问我的flask应用程序上运行的这个URL时,我希望web服务能够处理问号后指定的参数:

http://10.1.1.1:5000/login?username=alex&password=pw1

#I just want to be able to manipulate the parameters
@app.route('/login', methods=['GET', 'POST'])
def login():
    username = request.form['username']
    print(username)
    password = request.form['password']
    print(password)

我正在寻找一种方法来包装api的默认功能在我的基于php的web应用程序,数据库和cms。

我环顾四周,发现了几个“骨架”框架。除了我的问题的答案之外,还有一个我喜欢的REST框架Tonic,因为它非常轻量级。

我最喜欢REST,因为它简单,并希望基于它创建一个API体系结构。我正在努力理解基本原理,但还没有完全理解。因此,有一些问题。

1. 我理解得对吗?

假设我有一个资源“用户”。我可以像这样设置一些uri:

/api/users     when called with GET, lists users
/api/users     when called with POST, creates user record
/api/users/1   when called with GET, shows user record
               when called with PUT, updates user record
               when called with DELETE, deletes user record

到目前为止,这是RESTful体系结构的正确表示吗?

2. 我需要更多的动词

创建、更新和删除在理论上可能已经足够了,但实际上我需要更多的动词。我知道这些东西可以嵌入到更新请求中,但它们是特定的操作,可以有特定的返回代码,我不想把它们都扔到一个操作中。

在用户示例中想到的一些是:

activate_login
deactivate_login
change_password
add_credit

我该如何表达像RESTful URL体系结构那样的动作呢?

我的直觉是对URL进行GET调用

/api/users/1/activate_login 

并等待状态码返回。

但是,这偏离了使用HTTP谓词的想法。你怎么看?

3.如何返回错误消息和代码

A great part of REST's beauty stems from its use of standard HTTP methods. On an error, I emit a header with a 3xx,4xx or 5xx error status code. For a detailed error description, I can use the body (right?). So far so good. But what would be the way to transmit a proprietary error code that is more detailed in describing what went wrong (e.g. "failed to connect to database", or "database login wrong")? If I put it into the body along with the message, I have to parse it out afterwards. Is there a standard header for this kind of thing?

4. 如何进行身份验证

遵循REST原则的基于API密钥的身份验证是什么样子的? 除了公然违反REST原则之外,在验证REST客户机时使用会话是否有强烈的反对之处?:)(这里只是半开玩笑,基于会话的身份验证在我现有的基础设施中可以很好地发挥作用。)

当涉及到REST API的返回错误时,我正在寻找关于良好实践的指导。我正在开发一个新的API,所以我现在可以把它带到任何方向。目前我的内容类型是XML,但我计划将来支持JSON。

I am now adding some error cases, like for instance a client attempts to add a new resource but has exceeded his storage quota. I am already handling certain error cases with HTTP status codes (401 for authentication, 403 for authorization and 404 for plain bad request URIs). I looked over the blessed HTTP error codes but none of the 400-417 range seems right to report application specific errors. So at first I was tempted to return my application error with 200 OK and a specific XML payload (ie. Pay us more and you'll get the storage you need!) but I stopped to think about it and it seems to soapy (/shrug in horror). Besides it feels like I'm splitting the error responses into distinct cases, as some are http status code driven and other are content driven.

那么行业建议是什么呢?好的实践(请解释为什么!),并且,从客户端角度来看,REST API中什么样的错误处理可以使客户端代码更容易?

我读过关于SOAP和REST作为web服务通信协议的区别的文章,但是我认为REST相对于SOAP的最大优势是:

REST更加动态,不需要创建和更新UDDI(通用描述、发现和集成)。 REST不仅限于XML格式。RESTful web服务可以发送纯文本/JSON/XML。

但是SOAP更加标准化(例如:安全性)。

那么,这些点我说对了吗?