1

I am trying to send post request using ruby and net/http, but can't pass X-WSSE header. Here is my code:

require 'net/http'
require 'uri'
uri = URI.parse("http://exampleurl.com")
http = Net::HTTP.new(uri.host)
request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/x-www-form-urlencoded'})

request['X-WSSE'] = {
  '/' => "UsernameToken",
  'Username' => "xxxxx",
  'PasswordDigest' =>"xxxxxx",
  'Nonce' => "xxxxxx",
  'Created'=> "2016-06-12T01:24:13Z"
}

request['Authorization'] = {
  '/' => "WSSE",
  'realm' => "SDP",
  'profile' =>"UsernameToken",
  'type' => "AppKey"
}


request.set_form_data(
  "from" => "sender",
  "to" => "phone_number",
  "body" => "12345",
)

response = http.request(request)

But I always get error 400(No X-WSSE found in HTTP-Header), however curl request works perfectly, can you help me?

Here is curl request that works well

curl -X POST -H "Authorization: WSSE realm=\"SDP\", profile=\"UsernameToken\", type=\"AppKey\"" -H "X-WSSE: UsernameToken Username=\"xxxxxxx\", PasswordDigest=\"xxxxxxxxx=\", Nonce=\"xxxxxxx\", Created=\"2016-06-12T01:11:19Z\" " -H "Content-Type: application/x-www-form-urlencoded" -H "Cache-Control: no-cache" -d 'from=xxxxx&to=xxxxxx&body=1234' "http://api.oneapi.ru/sms/sendSms/v1"
weras
  • 11
  • 4

0 Answers0