标签: rest-client

使用带有多部分帖子的restclient

我正在使用restclient进行多部分表单将数据发送到一个宁静的Web服务(它是Panda视频编码服务).但问题是,我传递给restclient(Technoweenie分支)的文件来自我自己提交的用户提交的表单.

所以,让我们来看看吧.用户将文件发布到我的rails应用程序.在我的控制器中,它从params [:file]接收文件.然后我想使用RestClient将params [:file]传递给Panda.

我得到的错误是在熊猫服务器上.我注意到堆栈跟踪中的文件参数也是一个字符串(我假设是Panda变成一个字符串以获得更好的堆栈跟踪).

 ~ Started request handling: Wed Aug 12 18:05:15 +0000 2009
 ~ Params: {"format"=>"html", "multipart"=>"true", "account_key"=>"SECURE_KEY", "action"=>"upload", "id"=>"SECURE_ID", "controller"=>"videos", "file"=>"#<File:0xcf02ca4>"}
 ~ 9bfb1750-6998-012c-4509-12313900b0f6: (500 returned to client) InternalServerErrorcan't convert nil into String
/var/local/www/panda/app/models/video.rb:246:in `extname'
/var/local/www/panda/app/models/video.rb:246:in `initial_processing'
/var/local/www/panda/app/controllers/videos.rb:79:in `upload'
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails rest-client

6
推荐指数
1
解决办法
2579
查看次数

如何使用RestClient进行Rails基本授权?

我正在尝试使用rest-client向REST服务(HP ALM 11 REST API fwiw)发布请求并继续获取未经授权的响应.可能是我没有正确地遵循文档,但我也不确定我正在正确地处理标题.到目前为止,我在Google上搜索RestClient一直没有结果.任何帮助,将不胜感激:

码:

@alm_url       = "http://alm_url/qcbin/"
@user_name     = "username"
@user_password = "password"

authentication_url = @alm_url + "rest/is-authenticate"
resource = RestClient::Resource.new authentication_url
resource.head :Authorization => Base64.encode64(@user_name) + ":" + Base64.encode64(@user_password)
response = resource.get


#response = RestClient.get authentication_url, :authorization => @username, @user_password
Rails.logger.debug response.inspect
Run Code Online (Sandbox Code Playgroud)

基于这个SO问题,我也尝试了以下但没有成功:

@alm_url       = "http://alm_url/qcbin/"
@user_name     = "username"
@user_password = "password"

authentication_url = @alm_url + "rest/is-authenticate"
resource = RestClient::Resource.new authentication_url, {:user => @user_name, :password => @user_password}
response = resource.get


#response = RestClient.get authentication_url, …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rest-client ruby-on-rails-3.1

6
推荐指数
1
解决办法
5642
查看次数

在Rails应用程序中记录RestClient

我想调试我的Rails应用程序使用RestClient进行的请求.RestClient文档说:

要启用日志记录,您可以

使用ruby Logger设置RestClient.log或设置环境变量以避免修改代码(在这种情况下,您可以使用文件名"stdout"或"stderr"):

$ RESTCLIENT_LOG = stdout path/to/my/program生成这样的日志:

RestClient.get" http:// some/resource "

=> 200 OK | text/html 250个字节

RestClient.put" http:// some/resource ","payload"

=> 401未经授权| application/xml 340字节

请注意,这些日志是有效的Ruby,因此您可以将它们粘贴到restclient shell或>脚本中以重放您的休息调用序列.

如何将这些日志包含在我的Rails应用程序日志文件夹中?

logging ruby-on-rails rest-client

6
推荐指数
3
解决办法
7327
查看次数

是否有一个良好类型的Scala(或Java)库来使用JSON Web API?

我想要一个简单的Java(或Scala)休息客户端库,让我可以轻松地在JSON REST API上执行GET/PUT/POST/DELETE等,并以类型安全的方式将JSON响应反序列化为Java对象,例如

RestClient client = new RestClient("http://api.mycompany.com").withAuth(Auth.Basic, username, password);
// This basically deserializes the JSON response into a POJO    
MyDocument[] result = client.get("/document?limit=10", MyDocument[].class);
MyFriend friend = client.post("/friend/Joe", body, MyFriend.class); 
Run Code Online (Sandbox Code Playgroud)

基本上我希望通用签名是这样的,get()例如 public <T> T get(String path, Class<T> responseClass),它会执行GET请求并将JSON响应反序列化为类型的POJOresponseClass

我确实找到了一个非常接近我想要的站点库的库,但它的范围受到严重限制,例如它不允许我做更多不常见的HTTP动词,如PUT/PATCH/DELETE,它无法设置标题或甚至是请求的正文.

我找到的另一个库有相反的问题 - 它无法进行basicauth,也没有为您将JSON序列化为对象.

java json scala rest-client sitebricks

6
推荐指数
1
解决办法
1853
查看次数

Fusion Tables:在尝试通过Ruby的RestClient gem更新表格样式时,为什么我一直收到"400 Bad Request"错误

我正在尝试使用Ruby gem RestClient更新我的一个Fusion Tables的样式.

这是我的代码:

require 'rest_client'

tableId = '<STRING CONTAINING TABLEID>'
styleId = '<STRING CONTAINING STYLEID>'
key = '<STRING CONTAINING MY FUSION TABLES API KEY>'

table_url = "https://www.googleapis.com/fusiontables/v1/tables/#{tableId}/styles/#{styleId}?key=#{key}"
update = '{"polygonOptions": {"strokeColor":"#ffffff"}}'

token = 'STRING CONTAINING AUTHORIZATION TOKEN'

RestClient.put table_url,update,{"Authorization" => "Bearer #{token}"}
Run Code Online (Sandbox Code Playgroud)

当我运行该代码时,我收到此错误:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!': 400 Bad Request (RestClient::BadRequest)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit'
    from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:745:in `start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient.rb:80:in `put'
Run Code Online (Sandbox Code Playgroud)

当我将update代码输入到Google官方Style请求PUT制造商的东西时,更新有效.但是当我运行我的Ruby代码时它不起作用.

有谁知道我做错了什么? …

ruby oauth put rest-client google-fusion-tables

6
推荐指数
1
解决办法
3430
查看次数

使用Rest Client Ruby Gem的身份验证标头

我已经创建了一个基本的身份验证密钥,现在我只是想利用它.我尝试了一些不同的变体,但似乎没有一个在请求标题中显示授权.

$auth = 'Basic cmFtZXNoQHVzYW1hLmNvbTpyYW1lc2h1JEBtcA=='


@response = resource.post('Authorization' => $auth)
nor
@response = resource.post(:authorization => $auth)
nor
@response = resource.post(:Authorization => $auth)
nor
@response = resource.post(:content_type => :json, :accept => :json, :headers => { 'Authorization:' => $auth })
Run Code Online (Sandbox Code Playgroud)

不幸的是,我没有在rdoc中找到很多可以帮助我解决这个问题的信息.有没有人有使用Rest Client gem添加auth标头的经验?

ruby rest rest-client

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

如何让Ruby的RestClient使用多值查询参数?

使用RestClient gem,我需要创建一个如下所示的请求:

GET http://host/path?p=1&p=2
Run Code Online (Sandbox Code Playgroud)

完成此任务的正确语法是什么?请注意,接收主机不是Rails.

尝试:

resource = RestClient::Resource.new( 'http://host/path' )
params = { p: '1', p: '2' }  
# ^ Overrides param to have value of 2 (?p=2)

params = { p: ['1','2'] }
# ^ results in 'p[]=abc&p[]=cde' (array [] indicators not wanted)

resource.get( { params: params } )
Run Code Online (Sandbox Code Playgroud)

ruby rest-client

6
推荐指数
1
解决办法
1826
查看次数

如何使用PhpStorm REST CLIENT传递POST参数

POST参数在请求正文中传递

我需要以哪种格式在PhpStorm REST CLIENT中传递它们?

我试过了

param = value param:value

什么都行不通.任何帮助赞赏

rest-client phpstorm

6
推荐指数
1
解决办法
6620
查看次数

如何在java中缓存REST API响应

我正在java中构建一个应用程序.我在循环中点击api超过15000次并获得响应(响应仅为静态)

**
  username in for loop   
  GET api.someapi/username
  processing
  end loop
**
Run Code Online (Sandbox Code Playgroud)

完成所有通话需要几个小时.建议我以任何方式(任何缓存技术)来减少通话时间.

PS:

1)我从java rest客户端(Spring resttemplate)命中api

2)我打的是公开的,不是我开发的

3)将部署在heroku中

rest spring caching rest-client spring-cache

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

如何在 Microprofile REST 客户端动态添加 HTTP 标头?

我正在开发使用 microprofile Rest 客户端的应用程序。该 REST 客户端应发送带有各种 http 标头的 REST 请求。某些标头名称会动态更改。我的微配置文件休息客户端应该是通用的,但我没有找到如何实现这种行为。根据文档,您需要通过注释指定实现中的所有标头名称,但这不是通用的。有什么方法可以“破解”它并以编程方式添加 HTTP 标头吗?

提前致谢

 GenericRestClient genericRestClient = null;
 Map<String, Object> appConfig = context.appConfigs();
 String baseUrl = (String) appConfig.get("restClient.baseUrl");
 path = (String) appConfig.get("restClient.path");
 try {
     genericRestClient = RestClientBuilder.newBuilder()
                .baseUri(new URI(baseUrl)).build(GenericRestClient.class);
 }catch(URISyntaxException e){
      logger.error("",e);
      throw e;
 }

Response response = genericRestClient.sendMessage(path, value);
logger.info("Status: "+response.getStatus());
logger.info("Response body: "+response.getEntity().toString());
Run Code Online (Sandbox Code Playgroud)

通用休息客户端代码:

@RegisterRestClient
public interface GenericRestClient {
    @POST
    @Path("{path}")
    @Produces("application/json")
    @Consumes("application/json")
    public Response sendMessage(<here should go any map of custom headers>, @PathParam("path") String pathParam, String jsonBody);
}
Run Code Online (Sandbox Code Playgroud)

java rest-client microprofile

6
推荐指数
1
解决办法
5664
查看次数