让我开始使用 fopen/curl 请求的非常快速的示例
我希望开始从 comindwork 中提取数据,但我以前从未使用过任何网络服务,所以我真的不知道如何开始。
有人建议我可以使用 fopen 拉回数据或发送curl 请求,但我不知道是哪一个。
我正在使用这个 api:
项目 取回 获取所有项目
GET /projects.xml
GET|POST /project/list
获取一个项目
GET /projects/{project_id}.xml
GET|POST /project/show/{project_id}
GET /projects/{project_id}
哪个项目可以完成这项工作,您能否提供一个简单的示例?
谢谢
I am looking to start pulling data from comindwork, but I have never used any web services before so I don't really know how to get started.
Someone has suggested I can pull back data with either fopen or send a curl request, but I don't know which one.
I am using this api:
Projects
RETRIEVE
Get All Projects
GET /projects.xml
GET|POST /project/list
Get One Project
GET /projects/{project_id}.xml
GET|POST /project/show/{project_id}
GET /projects/{project_id}
Which one will do the job and could you provide a quick example please?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于fopen与curl:总是更喜欢curl,特别是当使用它超过1次时。
除了灵活性等显而易见的原因之外,curl 的速度仅快 5 倍左右。
regarding fopen vs curl: always prefer curl, especially when using it more than 1 time.
Obvious reasons like flexibility aside, curl is just about 5 times faster.
由于您需要能够 POST 和 GET,curl 将是一个不错的选择(尽管您可以轻松地使用两者 - fopen 用于 GET,curl 用于 POST)。
使用curl 的示例POST:
这是一个基本示例,需要针对生产应用程序进行改进。例如,您可能需要使用curl_getinfo() 检查响应信息。
使用 fopen 的 GET 示例:
缺点是如果服务器返回有意义的标头,您将无法读取它们。最好使用 file_get_contents:
然后您就可以查阅 $http_response_header 变量来获取返回的标头。
Since you need to be able to POST as well as GET, curl would be a good choice (although you could easily use both - fopen for GET and curl for POST).
example POST using curl:
This is a basic example which would need improvement for a production app. For example, you'd probably need to check response information using curl_getinfo().
example GET using fopen:
A downside is that if the server returns meaningful headers, you can't read them. Better to use file_get_contents:
You'd then be able to consult the $http_response_header variable to get the returned headers.
我会看看 http://www.phpclasses.org/package/3329-PHP-HTTP-client-using-the-PHP-Curl-library.html这是一个简单的、注释良好的curl包装器,可以为您提供如何的想法它有效=)
I'd have a look at http://www.phpclasses.org/package/3329-PHP-HTTP-client-using-the-PHP-Curl-library.html which is a simple, well commented wrapper around curl that could give you an idea of how it works =)