我使用RestClient gem向一些服务发送PUT请求。我这样做:
RestClient.put('http:/app.com/resource/:id.json', { app_token: 'xxx', resource: { status: 'NNN' }})
但答案JSON是空的(不会返回我需要的东西)。如果我发送这样的请求:
RestClient.put('http:/app.com/resource/:id.json?app_token=XXX&resource[status]=NNN', {})
然后一切正常(JSON正常)。我的代码出了什么问题?谢谢!
P.S。经度:
1)RestClient.put" http:/app.com/resource/:id.json"," app_token = XXX& resource [status] = NNN",&#34 ;接受" = GT;" / 的; q = 0.5,application / xml"," Accept-Encoding" =>" gzip,deflate"," Content-Length" =>&# 34; 73","内容类型" =>" application / x-www-form-urlencoded"
#=> 200 OK | application / json 12字节 (空JSON)
2)RestClient.put" http:/app.com/resource/:id.json?app_token = XXX& resource [status] = NNN","接受" => ;" / 的; q = 0.5,application / xml"," Accept-Encoding" =>" gzip,deflate"
#=> 200 OK | application / json 37 bytes (有效JSON)
答案 0 :(得分:0)
我认为应该写成:
RestClient.put('http:/app.com/resource/:id.json', nil,{params: { app_token: 'xxx', resource: { status: 'NNN' }}})
请参阅https://github.com/rest-client/rest-client#query-parameters
答案 1 :(得分:0)
你为什么不试试这个呢?更清晰的语法。
@options = {
params: {
app_token: 'xxx',
resource: {
status: 'NNN'
}
}
}
RestClient.put("http:/app.com/resource/:id.json", @options)