"phil@gmail.com", "token" => "mytok-6ren">
gpt4 book ai didi

ruby-on-rails - HTTParty针对Rails的内容类型问题

转载 作者:行者123 更新时间:2023-12-04 07:32:20 25 4
gpt4 key购买 nike

require 'HTTParty'
require 'json'

@payload ={
"email" => "phil@gmail.com",
"token" => "mytokenstuff",
"content" => "here is some content",
"notification_type" => "1",
"name" => "here is a name",
"auto_action" => "true"
}

response = HTTParty.post('http://localhost:3000/api/create.json', :body =>JSON.dump(@payload), :headers => { 'Content-Type' => 'application/json' } )

在我的rails Controller 中,标题位于ContentType text/html中。所以很明显我的标题参数不起作用...

想法?

最佳答案

尝试这种方式:

HTTParty.post(
'http://localhost:3000/api/create.json',
:body => JSON.dump(@payload),
:headers => {
'Content-Type' => 'application/json',
}
)

也尝试添加 Accept:
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}

另外,请检查它是否没有从cookie中获取选项-清洁cookie。

关于ruby-on-rails - HTTParty针对Rails的内容类型问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11516241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com