ruby - 在 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 question或this question的解释。
解决方案
尝试传递字符串而不是数组。
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
})
推荐阅读
- sockets - EINPROGRESS 是否保证非阻塞连接失败?
- amazon-web-services - 在 Amazon S3 中将在 aws3 存储桶中创建的文件夹设为公共或私有文件夹
- kendo-ui - 第二次打开窗口尝试中的空白剑道窗口
- javascript - 如何制作具有彩色效果的粘性标题
- sphinx - Sphinx:如何停止提交的查询?
- android - 设备上没有这样的文件或目录
- php - 仅在某个特定字段更新时添加注释
- java - 在 Maven 多模块项目的各个模块的测试之间保留 h2 数据库
- python - 使用连续名称打印变量的问题
- jquery - 打开画布外菜单时调整内容大小
我正在尝试使用 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 question或this question的解释。
解决方案
尝试传递字符串而不是数组。
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
})
推荐阅读
- sockets - EINPROGRESS 是否保证非阻塞连接失败?
- amazon-web-services - 在 Amazon S3 中将在 aws3 存储桶中创建的文件夹设为公共或私有文件夹
- kendo-ui - 第二次打开窗口尝试中的空白剑道窗口
- javascript - 如何制作具有彩色效果的粘性标题
- sphinx - Sphinx:如何停止提交的查询?
- android - 设备上没有这样的文件或目录
- php - 仅在某个特定字段更新时添加注释
- java - 在 Maven 多模块项目的各个模块的测试之间保留 h2 数据库
- python - 使用连续名称打印变量的问题
- jquery - 打开画布外菜单时调整内容大小