HTTParty POST 正在发送 GET

HTTParty POST is sending a GET

我正在点击 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