我正在尝试使用 httparty gem 发出帖子请求。

    response = HTTParty.post(App.base_uri + "/api?service=post&action=update&version=2",
    body: [{"some_big_json": "w,ruby,httparty,net-http"/>
	














首页 > 解决方案 > 在 HTTParty 发布请求中将数组作为正文发送:未定义的方法 `bytesize' for #

我正在尝试使用 httparty gem 发出帖子请求。

    response = HTTParty.post(App.base_uri + "/api?service=post&action=update&version=2",
    body: [{"some_big_json": "w

问题描述

我正在尝试使用 httparty gem 发出帖子请求。

    response = HTTParty.post(App.base_uri + "/api?service=post&action=update&version=2",
    body: [{"some_big_json": "with many key value pair"}],
    headers: {
      'Content-Type' => 'application/json',
      'Accept' => 'application/json',
      'Cookie' => @@cookie
    })

Body 是一个数组。当我发出发布请求时,我收到此错误:

/home/user/.rbenv/versions/2.5.0/lib/ruby/2.5.0/net/http/generic_request.rb:183:in send_request_with_body': undefined method bytesize' for #<Array:0x00005561f96833e0> (NoMethodError)

如何使用 httparty 在正文中发布一个大数组?

更新:在邮递员中,我能够将正文作为数组发送,并且我得到了成功(预期)的响应。


在 matplotlib 3.0.2 和 2.1.2 中,使用

textprops = dict(va="center", rotation_mode = 'anchor')

(和labeldistance=1.05)导致

在此处输入图像描述

请注意,这忽略了该ha="center"选项,因为最好根据标签是在圆圈的左侧还是右侧自动设置水平对齐方式。

有关rotation_mode参见例如this questionthis question的解释。

标签: rubyhttpartynet-http

解决方案


尝试传递字符串而不是数组。

response = HTTParty.post(App.base_uri + "/api?service=post&action=update&version=2",
    body: "[{'some_big_json': 'with many key value pair'}]",
    headers: {
      'Content-Type' => 'application/json',
      'Accept' => 'application/json',
      'Cookie' => @@cookie
    })

推荐阅读