Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用net/http传递X-WSSE头ruby_Ruby On Rails_Ruby_Http_Curl_Wsse - Fatal编程技术网

Ruby on rails 使用net/http传递X-WSSE头ruby

Ruby on rails 使用net/http传递X-WSSE头ruby,ruby-on-rails,ruby,http,curl,wsse,Ruby On Rails,Ruby,Http,Curl,Wsse,我试图使用ruby和net/http发送post请求,但无法传递X-WSSE头。 这是我的密码: 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-for

我试图使用ruby和net/http发送post请求,但无法传递X-WSSE头。 这是我的密码:

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)
但我总是得到错误400(在HTTP头中找不到X-WSSE),然而curl请求工作得很好,你们能帮我吗

下面是一个运行良好的curl请求

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"

只需更改请求中“授权”和“X-WSSE”的顺序并执行即可。只需更改请求中“授权”和“X-WSSE”的顺序并执行即可。