如何使用Rest Client
执行以下查询(在doc中给出)。
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{
"query" : {
"term" : { "user" : "kimchy" }
}
}
'
我尝试这样做:
q = '{
"query" : {
"term" : { "user" : "kimchy" }
}
}
'
r = JSON.parse(RestClient.get('http://localhost:9200/twitter/tweet/_search', q))
这引发了一个错误:
in `process_url_params': undefined method `delete_if' for #<String:0x8b12e18> (NoMethodError)
from /home/socialapps/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:40:in `initialize'
from /home/socialapps/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `new'
from /home/socialapps/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
from /home/socialapps/.rvm/gems/ruby-1.9.3-p194/gems/rest-client-1.6.7/lib/restclient.rb:68:in `get'
from get_check2.rb:12:in `<main>'
当我使用进行相同的操作时RestClient.post
,它会给我正确的结果!但是elasticsearch doc
XGET
在curl命令中使用的不是搜索查询XPOST
。我该如何使用该RestClient.get
方法?
如果有其他/更好的方法来执行此操作,请提出建议。
RestClient无法使用发送请求正文GET
。您有两种选择:
将查询作为source
URL参数传递:
require 'rest_client'
require 'json'
# RestClient.log=STDOUT # Optionally turn on logging
q = '{
"query" : { "term" : { "user" : "kimchy" } }
}
'
r = JSON.parse \
RestClient.get( 'http://localhost:9200/twitter/tweet/_search',
params: { source: q } )
puts r
…或只是使用POST
。
更新: 修复了URL参数的错误传递,请注意params
哈希。
我想获取多个JSON数据,我以Json格式以正文的形式传递给邮递员。 如果我传递单个json数据,例如:{"firstName":"ria","lastName":"soni"}",这样我就可以在下面提到的JavaAPI中获取它: 它工作正常。但是如果我想传递[{"firstName":"ria","lastName":"soni"},{"firstName":"shreya","lastName
@test public void generateToken(){ } 当以上述方式发送时,得到错误的请求。
我已经查看了各种答案,但它们并没有解决我的问题。我有一个非常具体的客户需求,我无法使用请求的主体。 我已经检查了这些帖子: 尝试使用Spring Boot REST从POST读取JSON字符串 使用Jackson JSON在Spring MVC中解析JSON 在Rest web方法中传递JSON对象 注意:我确实对URI进行了编码。 我得到各种错误,但非法的超文本标记语言字符是一个。要求很简单:
我正试图在post请求负载中传递数组。 有效载荷: 我所做的是: 但我得到的回应是: “找不到请求数据”
我和Gremlin.Net一起工作
正在尝试使用asp。net和mvc。 我有一个像这样的< code>Weather类: 我用来发出< code>GET请求的方法如下所示: 我请求的 URI 返回 JSON 对象。 我想访问< code >“Weather”对象,提取属性< code>main和< code>description,并在我的< code>GetWeather中返回一个列表,其中< code>JSON对象的天气属性与