如何使用Dart HttpClient进行DELETE请求? [英] How can DELETE requests be made with a Dart HttpClient?
问题描述
如果您使用Dart HttpClient
(提供 HttpClientRequest
)从服务器发出请求另一个服务器,只要我能告诉只有HTTP方法可用的是 GET
和 POST
post
/ postUrl
和 get
/ getUrl
函数)。是否还有一种方法使 PUT
和 DELETE
请求?
If you're using a Dart HttpClient
(which provides an HttpClientRequest
) to make requests from a server to another server, as far as I can tell the only HTTP methods available are GET
and POST
(corresponding, respectively, to the post
/postUrl
and get
/getUrl
functions). Is there also a way to make PUT
and DELETE
requests?
推荐答案
您应该可以使用打开方法,它允许您使用任何HTTP动词:
You should be able to do with this with the open method which allows you to use any HTTP verb:
client.open('delete', 'http://example.com', '8080', '/test');
如果您查看 HttpClient来源,您会看到 get
和 post
方法只是打开
的别名:
If you look at the HttpClient source you'll see that the get
and post
methods are just aliases for open
anyway:
Future<HttpClientRequest> post(String host,
int port,
String path) {
return open("post", host, port, path);
}
这篇关于如何使用Dart HttpClient进行DELETE请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!