So I am trying to send a post request using a json payload and it works fine from the command line using curl:
curl -k -v -H "content-type: application/json" -H "Host: ,myapp:3000" --data @payload.json https://ip:port/myapi
This is my payload.json:
{
"Template":"Client",
"Data":"-----BEGIN CERTIFICATE REQUEST-----\nMIICwzCCAasCAQAwfjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1EMRYwFAYDVQQH\nEw1TaWx2ZXIgU3ByaW5nMQ0wCwYDVQQKDARPU1BMMQ0wCwYDVQQLDAR0ZXN0MQ0w\nCwYDVQQDDARPU1BMMR0wGwYJKoZIhvcNAQkBDA50ZXN0QGdtYWlsLmNvbTCCASIw\nDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN5PCkBN6/F+ycllp0ILpNukuwPS\nq0LRtts1pPiLfCdKGwGbXwTuxExFBMvgxRKbHEq+wt1W5r4yQbpSegQnK4uqzNDS\n41/1g+dnOpRIsznYB00AGlrhhwwTWP9mRpF0PXQ688y185z7XI0LPZOFHZUmyelM\nReK8X5bBfzmgEJ17BXRAhZOR36/p0CsGrxUxA99cTAC47dMuQr+mZu5IPdzKNMbI\n5QnhDA/0sfFjjVHbHKqGnIa+qaPJgcS31usF6RAbTLeOASa/5Sn2LD8kd8actFcw\n3/vND0bGgvU/USKR3bNRNTAqfzNydRljLF2iRM8p4G4Dr2ZeFCb6jsPB9n0CAwEA\nAaAAMA0GCSqGSIb3DQEBBQUAA4IBAQCFTP9YukPR4Zex+jqQ3tmqMeOkLxMNAaQQ\nmBzN17bFRIs7UvP3nTi0Gme7QOAMOuqb6vwuWVRX9iApVmRNL9qYlPT7VXiZnNGi\nQue18Pwb5MoL4nJ2A8xGeB7Ojaec2RO2quLlUM3xOSdV53epcqdVhtW7XX1OTxYZ\n/8IBPhCPg/YPbKLnUERxFQMEyxYNf8mFfBa/PUNYtSsv8fdCAzqMQZVE7v8zJkXA\nwoE3M5kDjJ7fWpQ0KfIxu7mzWq/RkHUdGiI4uJBPOTwtfjbOjUI3JZ5x+SJwuaoE\nJdkKZ/Q5GfgChbKAik3peHfkMtIpmZQkuF54T9JSS0NbYlJhvjEr\n-----END CERTIFICATE REQUEST-----\n"
}
But when i try to the same from my ruby code it gives a 400 bad request error:
def generate_cert
payload = {
"Template"=> "Client",
"Data"=> "-----BEGIN CERTIFICATE REQUEST-----\nMIICwzCCAasCAQAwfjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1EMRYwFAYDVQQH\nEw1TaWx2ZXIgU3ByaW5nMQ0wCwYDVQQKDARPU1BMMQ0wCwYDVQQLDAR0ZXN0MQ0w\nCwYDVQQDDARPU1BMMR0wGwYJKoZIhvcNAQkBDA50ZXN0QGdtYWlsLmNvbTCCASIw\nDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN5PCkBN6/F+ycllp0ILpNukuwPS\nq0LRtts1pPiLfCdKGwGbXwTuxExFBMvgxRKbHEq+wt1W5r4yQbpSegQnK4uqzNDS\n41/1g+dnOpRIsznYB00AGlrhhwwTWP9mRpF0PXQ688y185z7XI0LPZOFHZUmyelM\nReK8X5bBfzmgEJ17BXRAhZOR36/p0CsGrxUxA99cTAC47dMuQr+mZu5IPdzKNMbI\n5QnhDA/0sfFjjVHbHKqGnIa+qaPJgcS31usF6RAbTLeOASa/5Sn2LD8kd8actFcw\n3/vND0bGgvU/USKR3bNRNTAqfzNydRljLF2iRM8p4G4Dr2ZeFCb6jsPB9n0CAwEA\nAaAAMA0GCSqGSIb3DQEBBQUAA4IBAQCFTP9YukPR4Zex+jqQ3tmqMeOkLxMNAaQQ\nmBzN17bFRIs7UvP3nTi0Gme7QOAMOuqb6vwuWVRX9iApVmRNL9qYlPT7VXiZnNGi\nQue18Pwb5MoL4nJ2A8xGeB7Ojaec2RO2quLlUM3xOSdV53epcqdVhtW7XX1OTxYZ\n/8IBPhCPg/YPbKLnUERxFQMEyxYNf8mFfBa/PUNYtSsv8fdCAzqMQZVE7v8zJkXA\nwoE3M5kDjJ7fWpQ0KfIxu7mzWq/RkHUdGiI4uJBPOTwtfjbOjUI3JZ5x+SJwuaoE\nJdkKZ/Q5GfgChbKAik3peHfkMtIpmZQkuF54T9JSS0NbYlJhvjEr\n-----END CERTIFICATE REQUEST-----\n"
}
encoded = payload.to_json
response = RestClient::Resource.new(
'https://myapi-url/',
).post encoded, :content_type => 'application/json'
p "Saving REST Client Response..."
response_json = JSON.parse(response.body)
return response_json
end
I also tried removing the to_json part above, but same result
Aucun commentaire:
Enregistrer un commentaire