我知道数据是通过HTTP传递的,但我不确定是否应该通过HTTP头或HTTP主体传递数据。API的约定是哪一种?
另外,理论上使用PHP,哪个更容易处理?据我所知,使用标头似乎是最简单的方法。
POST /api/v1/test_params.json HTTP/1.1
Host: rollrbla.de
Content-Length: 59
X-Target-URI: http://rollrbla.de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Connection: Keep-Alive
Test-Parameter-1=Test-value-1&Test-Parameter-2=Test-Value-2POST /api/v1/test_params.json HTTP/1.1
Test-Parameter-2: Test-Value-2
Host: rollrbla.de
Test-Parameter-1: Test-Value-1
Content-Length: 0
X-Target-URI: http://rollrbla.de
Connection: Keep-Alive总的来说,处理这些数据的最佳方法是什么,约定是什么?
发布于 2016-01-11 21:35:58
身体
报头应该描述请求,而不是封装其有效负载。
标头是元数据。
发布于 2016-01-11 21:20:30
我看了使用body参数和头参数的请求是什么样子的,还有一些PHP示例(感谢@RobertHarvey),我的结论是,body参数是最好的方法,因为它们不需要在PHP中读取任何特殊的函数。我只是不知道它们是什么,但现在我完全明白了。
POST /api/v1/test_params.json HTTP/1.1
Host: rollrbla.de
Content-Length: 59
X-Target-URI: http://rollrbla.de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Connection: Keep-Alive
Test-Parameter-1=Test-value-1&Test-Parameter-2=Test-Value-2..。是最好的方法。感谢所有帮助我得出这个结论的人。
https://softwareengineering.stackexchange.com/questions/307108
复制相似问题