标签: rest-client

超时和打开超时有什么区别?

在Ruby RestClient gem中,超时和开放超时功能之间的区别是什么?

http://www.ruby-doc.org/gems/docs/w/wgibbs-rest-client-1.0.5/RestClient/Resource.html#method-i-open_timeout

我也没有从gem的doc文件中得到任何东西.

ruby rest-client

10
推荐指数
1
解决办法
5744
查看次数

阅读400响应的主体?

我试图用rest-client宝石阅读400响应的主体.问题是rest-client通过将它作为一个错误来回应400,所以我无法找出任何方法来获取正文.

这是激励性的例子.考虑这个对facebook图API的调用:

JSON.parse(RestClient.get("https://graph.facebook.com/me?fields=id,email,first_name,last_name&access_token=#{access_token}"))
Run Code Online (Sandbox Code Playgroud)

如果access_token过期或无效,Facebook会做两件事:

  1. 返回400 Bad Request HTTP响应
  2. 返回响应正文中的JSON,其中包含更多信息,如下所示:
{
   "error": {
      "message": "The access token could not be decrypted",
      "type": "OAuthException",
      "code": 190
   }
}
Run Code Online (Sandbox Code Playgroud)

因为400响应引发了错误,我无法弄清楚如何获得响应的主体.也就是说,例如,如果我在curl或浏览器中运行上面的GET请求,我可以看到正文,但我无法弄清楚如何在restclient中访问它.这是一个例子:

begin
  fb_response = JSON.parse(RestClient.get("https://graph.facebook.com/me?fields=id,email,first_name,last_name&access_token=#{access_token}"))
rescue => e
  # 400 response puts me here
  # How can I get the body of the above response now, so I can get details on the error?
  # eg, was it an expired token?  A malformed token?  Something else?
end
Run Code Online (Sandbox Code Playgroud)

ruby rest-client

10
推荐指数
1
解决办法
5788
查看次数

如何从Groovy RestClient输出生成的请求和响应?

我目前正在使用RestClient,似乎无法弄清楚如何输出请求xml和响应xml用于调试和信息目的...

我尝试了这里提到的解决方案:http: //agileice.blogspot.com/2009/09/pretty-printing-xml-results-returned.html

但这没有奏效,还有其他任何建议吗?

rest groovy rest-client

9
推荐指数
2
解决办法
6348
查看次数

谷歌io 2010中的其他客户端应用程序设计方法是否仍然是最新的?

两年过去了,有片段,意图服务,游标加载器.方法是否仍然是最新的,或者是否有任何更好或成熟的模式来设计Android休息客户端,特别是与选项B相比(我没有权限发布图像,而是可以从这篇文章中找到图像).

我知道内容提供商部分是必不可少的.那么服务助手和服务组件呢?到目前为止,startService方法是Context或其子类的本质.这意味着服务助手将是一项活动.因此,从内容提供商发起活动是优雅的,还是应该从顶部的活动开始.

  • 对于那些深入研究google io 2011 iosched应​​用程序源代码的人,您是否会将HomeActivity中的静态类SyncStatusUpdaterFragment视为服务帮助程序,虽然它无法启动SyncService,但它会收听来自SyncService的回调,触发UI的刷新.那可能被视为Virgil Dobjanschi方法的变化吗?

有服务,意图服务,asyncTask和线程.在我看来,意图服务适合于从远程服务器同步大量数据.这就是为什么他们在iosched中使用它.但常见的情况是只有部分项目将与远程服务器同步.意图服务太沉重了.甚至是服务方式.我们可以只使用内容提供程序中的asyncTask或线程或其中的某个组件来完成此类任务.或者是否有任何令人信服的理由使用该服务,并通过服务助手服务处理器路径.我说的是一个严肃的申请.

你有什么看法?

android rest-client googleio intentservice

9
推荐指数
1
解决办法
1625
查看次数

Spring Rest客户端异常处理

我正在使用春天RestTemplate来消耗休息服务(在春季休息时暴露).我能够消耗成功的场景.但对于负面情况,服务会返回错误消息和错误代码.我需要在我的网页中显示这些错误消息.

例如,对于无效请求,服务会抛出HttpStatus.BAD_REQUEST适当的消息.如果我把try-catch块转到catch块而我无法得到ResponseEntity对象.

try {
    ResponseEntity<ResponseWrapper<MyEntity>> responseEntity = restTemplate.exchange(requestUrl, HttpMethod.POST, entity,
        new ParameterizedTypeReference<ResponseWrapper<MyEntity>>() {
    });
    responseEntity.getStatusCode();
    } catch (Exception e) {
        //TODO How to get response here, so that i can get error messages?
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

如何获得ResponseWrapper例外情况?

我从这里开始阅读CustomRestTemplate,但无法确定哪一个最适合我的情况.ResponseExtractor

java rest spring rest-client

9
推荐指数
2
解决办法
2万
查看次数

获取csrf令牌以获取json发布请求到rails应用程序

我一直在使用rest-client访问我编写的rails应用程序.我写了一个快速脚本来登录并发布帖子请求.一切正常,但我必须解决这样一个事实,即如果你在json中请求表单,则不会提供authenticity_token.我不得不在其他地方做一个普通的html请求获取authenticity_token,然后将其包含在我作为帖子请求的一部分提交的json中.基本上我有一个快速的脏脚本,如下所示

private_resource = RestClient::Resource.new( 'https://mysite.com')

params =  {:user => {:email => 'user@mysite.com', :password => 'please'}}
#log in
login_response = private_resource['users/sign_in'].post(params, :content_type => :json, :accept => :json)
#get cookie
cookie = login_response.cookies
#get json  
json_response = private_resource['products/new'].get(:content_type => :json, :accept => :json, :cookies => cookie)
#another request that returns html form with authenticity token 
response_with_token = private_resource['products/new'].get( :cookies => cookie)
#extract token 
token = Nokogiri::XML(response_with_token).css('input[name=authenticity_token]').first.attr('value')
#update cookie
cookie = response_with_token.cookies
#populate form and insert token
form = JSON.parse(json_response)
form['name'] = "my …
Run Code Online (Sandbox Code Playgroud)

json csrf rest-client ruby-on-rails-3.1

8
推荐指数
1
解决办法
1万
查看次数

客户端发送的请求在语法上是不正确的().+ Spring,RESTClient

我正在使用JSON对象使用Spring MVC.当我想从RESTClient发送JSON对象时,我得到了

HTTP状态400 - 客户端发送的请求语法错误().

这是我的控制器

ObjectMapper mapper=new ObjectMapper();
@RequestMapping(value = "/addTask", method = RequestMethod.GET)
       public ModelAndView addTask(@RequestParam("json") String json) throws JsonParseException, JsonMappingException, IOException 
       {
          System.out.println("Json object from REST : "+json);
          Task task=(Task) mapper.readValue(json, Task);
          service.addService(task);
          return new ModelAndView("Result");
       }
Run Code Online (Sandbox Code Playgroud)

我的请求网址: http://localhost:8080/Prime/addTask

我的Json对象:

{"taskName":"nothing","taskId":1234,"taskDesc":"什么都没做"}

我也尝试在RESTClient中指定"Content-Type:application/json"但仍然得到相同的错误

spring json rest-client

8
推荐指数
2
解决办法
2万
查看次数

Ruby/Rails性能:OpenURI vs NET:HTTP vs Curb vs Rest-Client

我正在访问不同的数据服务器,我在不同的类中尝试了不同的方法,使用基本的http :: net,curb,rest-client和open-uri

(1)如何测量Ruby/Rails中的性能?(2)您认为哪种方法更快?

所有4种不同方法的示例代码:

  url = "..."
  begin 
    io_output = open(url, :http_basic_authentication => [@user_id, @user_password])
  rescue => e
    error = e.message #for debugging return this
    return '-'
  else 
    output = io_output.read 
Run Code Online (Sandbox Code Playgroud)

要么

require 'net/https'
uri = URI.parse("...")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true 
http.verify_mode = OpenSSL::SSL::VERIFY_PEER 
data = http.get(uri.request_uri) #http request status
res = Net::HTTP.get_response(uri)
puts res.body if res.is_a?(Net::HTTPSuccess)
Run Code Online (Sandbox Code Playgroud)

要么

require 'curb'
url = "..."
c = Curl::Easy.new(url) do |curl| 
curl.headers["Content-type"] = "application/json"
curl.headers["Authorization"] = "Token ..."
end …
Run Code Online (Sandbox Code Playgroud)

curl open-uri ruby-on-rails rest-client curb

8
推荐指数
1
解决办法
3265
查看次数

如何通过客户端证书使用 Insomnia Rest 客户端?

我正在尝试将 Insomnia 与客户端证书一起使用。我从 Insomnia 文档中遵循了此文档。我添加了我的证书 pem 文件和密码。

问题是我仍然收到此错误:

错误:无法连接到服务器。

你知道为什么吗?谢谢。

api rest client-certificates rest-client

8
推荐指数
1
解决办法
4万
查看次数

如何在 Spring WebClient 中一次设置多个标头?

我试图为我的休息客户端设置标题,但每次我必须写

webclient.get().uri("blah-blah")
         .header("key1", "value1")
         .header("key2", "value2")...
Run Code Online (Sandbox Code Playgroud)

如何使用 headers() 方法同时设置所有标题?

rest-client resttemplate java-8 spring-boot spring-webclient

8
推荐指数
2
解决办法
2万
查看次数