RESTful 请求中的 Json 对象到 uri 字符串 (PHP)
在 REST 请求 url 中传递不明确参数的正确方法是什么?
<代码> var requestObj = {
城市:“伦敦”,
税收:[
{ name: '所得税', value: '10%', 'applies_to': '工资支票'},
{ name: '销售税', value: '7.5%', 'applies_to': '销售'}
]
}
我如何向将接收该请求的 http://blah.com 发出该请求?
http://blah.com/city/london/taxes/现在做什么?
我之前检查过这个 来自 json 的 url 中的 php 数组 等等,但无济于事。
What is the proper way to pass ambiguous parameters in a REST request url?
var requestObj = {
city: 'London',
taxes: [
{ name: 'Income Tax', value: '10%', 'applies_to': 'paycheck'},
{ name: 'Sales Tax', value: '7.5%', 'applies_to': 'sales'}
]
}
How can I make that request to http://blah.com which will receive the request?
http://blah.com/city/london/taxes/Now What?
I have previously checked this
php array in url from json and many more but to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想在这里做什么?如果您要添加新条目,则在 RESTful API 中,您将使用
POST
请求。这意味着参数甚至不会出现在 URL 中。如果这是某种查询,您可以发送 base64 编码的参数。它并不优雅,甚至不是严格意义上的 RESTful,但它应该可以工作,除非 URL 变得太长。
编辑:您可以为税收数组定义自己的序列化,例如
.../所得税/10%/薪水/销售税/7.5%/销售额
(当然是urlencoded)。仍然不太好,但是这个和某种编码(如base64)是我唯一能想到的。What are you trying to do here? If you're adding a new entry, then in a RESTful API you'd use a
POST
request. This means that the parameters won't even appear in the URL.If this is some sort of query, you could maybe send the parameters base64 encoded. It's not elegant, it's not even strictly RESTful, but it should work unless the URL becomes too long.
Edit: You could define your own serialization for the taxes array, something like
.../Income Tax/10%/paycheck/Sales Tax/7.5%/sales
(urlencoded, of course). Still not nice, but this and some kind of encoding (like base64) are the only things I can think of.