gpt4 book ai didi

ruby - HTTParty POST 正在发送 GET

转载 作者:数据小太阳 更新时间:2023-10-29 08:42:39 28 4
gpt4 key购买 nike

我正在访问 Github 的 v3 rest api ,我正在发出一个 POST 请求,试图在测试 PR 上创建评论。我收到了 200 响应,在检查请求时,它是作为 GET 而不是 POST 发送的:

response = HTTParty.post(
"http://api.github.com/repos/my_github/my_repo/issues/1/comments",
body: { body: "works" }.to_json,
headers: {
"Authorization": "Bearer #{ENV['GITHUB_TOKEN']}",
"Content-Type": "application/json",
"User-Agent": ENV["GITHUB_USER_AGENT"]
}
)

response.request
=> #<HTTParty::Request:0x007fdd45a42688
@http_method=Net::HTTP::Get,
@last_response=#<Net::HTTPOK 200 OK readbody=true>,
@last_uri=#<URI::HTTPS https://api.github.com/repos/my_github/my_repo/issues/1/comments>,
@options=
{:limit=>4,
:assume_utf16_is_big_endian=>true,
:default_params=>{},
:follow_redirects=>true,
:parser=>HTTParty::Parser,
:uri_adapter=>URI,
:connection_adapter=>HTTParty::ConnectionAdapter,
:body=>{:body=>"works"},
:headers=>
{:Authorization=>"Bearer my_token",
:Accept=>"application/vnd.github.machine-man-preview+json",
:"Content-Type"=>"application/json",
:"User-Agent"=>"me"}},
@path=#<URI::HTTPS https://api.github.com/repos/my_github/my_repo/issues/1/comments>,

响应主体是该 PR 上所有评论的列表,这是对同一 url 的 GET 请求。我不知道为什么它不发送 POST。感谢您的帮助。

最佳答案

更改您的请求以使用 HTTPS,而不是 HTTP:

https://api.github.com/repos/my_github/my_repo/issues/1/comments

代替:

http://api.github.com/repos/my_github/my_repo/issues/1/comments

你得到:

response.request
=> #<HTTParty::Request:0x00007ffdb81c7e48 @changed_hosts=false, @credentials_sent=false, @http_method=Net::HTTP::Post ...

还有:

response.code
=> 201

关于ruby - HTTParty POST 正在发送 GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53891933/

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