我正在尝试使用http POST请求将XML / SOAP数据发送到服务器,并且首先将工作的Perl脚本转换为Ruby on Rails。使用some resources,我已经编写了一些初步代码,但我不确定如何添加用户身份验证(运行此代码会导致连接超时错误)。
到目前为止我的代码:
http = Net::HTTP.new(' [host] ', [port])
path = '/rest/of/the/path'
data = [ XML SOAP string ]
headers = {
'Content-Type' => 'application/atom+xml',
'Host' => ' [host] '
}
resp, data = http.post(path, data, headers)
添加http.basic_auth 'user', 'pass'
给了我一个无方法错误
提供凭据的Perl代码:
my $ua = new LWP::UserAgent(keep_alive=>1);
$ua->credentials($netloc, '', "$user", "$pwd");
...
my $request = POST ($url, Content_Type=> 'application/atom+xml', Content=> $soap_req);
my $response = $ua->request($request);
服务器使用NTLM,所以也许你可以推荐一个gem(like this?)。看起来Perl脚本正在使用用户代理,所以我想在Ruby中做类似的事情。总之,如何在我的请求中添加用户身份验证?