Curl命令有效,但httparty请求给出403

时间:2017-12-01 23:09:27

标签: httparty

我有一个发出POST请求的curl命令,并返回正确的响应:

curl --data 'apiKey=someKey&apiSecureKey=someSecureKey&apiFunctionName=update&apiFunctionParams={"id”:”777”,”user_password":"password","invalid_login_attempts":"0","active_flag":"1"}' https://api-server.com/api-path/file.php

此外,当使用Postman时,如果我检查“form-data”按钮并将上面curl命令中的相同四个参数粘贴到Postman请求的主体中,则该请求有效。如果我检查Postman中的“x-www-form-urlencoded”按钮,我会收到403响应(见下文),这样我就认为这是一个标题问题。

我需要使用httparty复制此请求。这是我的尝试:

options = {
body: {
    apiKey: 'someKey',
    apiSecureKey: 'someSecureKey',
    apiFunctionName: 'update',
    apiFunctionParams: '{"id”:”777”,”user_password":"password","invalid_login_attempts":"0","active_flag":"1"}',
}
}

response = HTTParty.post("https://api-server.com/api-path/file.php", options)

这个请求给了我一个403 repsonse代码:

{"success":false,"response":"403","responseDesc":"Forbidden. Request is missing an API permission code.","params":{"id":"777","user_password":"password","invalid_login_attempts":"0","active_flag":"1"}}

如果我尝试添加标题,例如:

options = {
  headers: {'Content-Type' => 'multipart/form-data'},
  body: {
      apiKey: '20a030e47a28',
      apiSecureKey: '3a4e409e0c9f0e72e697fc288a88d751',
      apiFunctionName: 'update',
      apiFunctionParams: '{"id":"603","user_password":"password","invalid_login_attempts":"0","active_flag":"1"}',
  }

response = HTTParty.post("https://beta.fxptouch.com/classes/interface/user_profile.php", options)

我收到零回复。

0 个答案:

没有答案