我正在使用 PERL 和 SOAP::Lite 对 MS Exchange Web 服务进行肥皂调用。我已经弄清楚了身份验证并正在使用 Oauth 令牌进行调用。我正在尝试调用此处记录的 GetInboxRules。
基本上调用应该是这样的。
2 3 4 5 6 7 8 9 10 11 12 13 14 | <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <t:RequestServerVersion Version="Exchange2010_SP1" /> </soap:Header> <soap:Body> <m:GetInboxRules> <m:MailboxSmtpAddress>User1@Contoso.com</m:MailboxSmtpAddress> </m:GetInboxRules> </soap:Body> </soap:Envelope> |
我的第一次尝试使用了以下代码:
2 3 4 5 6 7 8 9 10 11 12 13 | $client->readable(1)->autotype(0)->outputxml('true'); $client->ns('http://schemas.microsoft.com/exchange/services/2006/messages', 'm'); my $ua = $client->schema->useragent; $ua->default_header('Authorization' => $auth_header); $ua->default_header('Content-Type' => 'application/xml'); $client->schema->useragent($ua); $client->transport->http_request->headers->push_header('Authorization'=> $auth_header); # WITH URI my $som = $client->call('GetInboxRules', SOAP::Data->name('MailboxSmtpAddress')->value('eg7636@foo.com')->uri('http://schemas.microsoft.com/exchange/services/2006/messages')); |
这产生了以下 XML 以及 500 内部服务器错误声明:
"请求未通过架构验证:命名空间 \\'http://schemas.microsoft.com/exchange/services/2006/messages\\' 中的元素 \\'GetInboxRules\\' 具有无效的子元素 \\'MailboxSmtpAddress\\' . 预期的可能元素列表:\\'MailboxSmtpAddress\\' 在命名空间 \\'http://schemas.microsoft.com/exchange/services/2006/messages\\'"
2 3 4 5 6 7 8 9 10 11 12 13 14 | <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <m:GetInboxRules> <MailboxSmtpAddress>eg7636@foo.com</MailboxSmtpAddress> </m:GetInboxRules> </soap:Body> </soap:Envelope> |
我已经在设置名称空间,但为了尝试解决这个问题,我通过向 MailboxSmtpAddress 元素添加 uri 规范来指定名称空间
产生:
2 3 4 5 6 7 8 9 10 11 12 13 14 | <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:namesp3="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <m:GetInboxRules> <namesp3:MailboxSmtpAddress xmlns:namesp3="http://schemas.microsoft.com/exchange/services/2006/messages">eg7636@foo.com</namesp3:MailboxSmtpAddress> </m:GetInboxRules> </soap:Body> </soap:Envelope> |
随后是 400 Bad Request 响应。我猜测错误的请求响应是因为 MailboxSmtpAddress 标记中包含 url,但我不知道如何指定命名空间。
这是我第一次使用 SOAP,因此非常感谢任何建议。
一位圣人救了我,并给了我以下代码:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ->readable(1) ->proxy('https://outlook.office365.com/EWS/Exchange.asmx') ->ns( 'http://schemas.microsoft.com/exchange/services/2006/types', 'typ') ->ns( 'http://schemas.microsoft.com/exchange/services/2006/messages', 'mes') ->envprefix('soapenv') ->autotype(0); $client->serializer->{'_attr'}{'{http://schemas.xmlsoap.org/soap/envelope/}encodingStyle'} = undef; $client->transport->default_header('Authorization' => $auth_header); $client->transport->default_header('X-AnchorMailbox' => 'eg7636@foo.onmicrosoft.com'); $client->transport->default_header('X-OWA-ExplicitLogonUser' => 'eg7636@foo.onmicrosoft.com'); my @header = ( SOAP::Header->name('typ:RequestServerVersion')->attr({'Version' => 'Exchange2015'}), SOAP::Header->name('typ:ExchangeImpersonation')->value(\\SOAP::Header->name('typ:ConnectingSID') ->value(\\SOAP::Header->name('typ:SmtpAddress')->value('eg7636@foo.com'))) ); my @param; my $method; @param = ( SOAP::Data->name('mes:MailboxSmtpAddress', 'eg7636@foo.com'), ); $method = SOAP::Data->name('mes:GetInboxRules'); my $response = $client->call($method => (@param, @header)); print Dumper($response); |
这导致命名空间标记被放置在传递给方法调用的元素上,并且还纠正了我在标题格式方面遇到的一些问题。
以下是来自该代码的 XML:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | xmlns:mes="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header> <typ:RequestServerVersion Version="Exchange2015" /> <typ:ExchangeImpersonation> <typ:ConnectingSID> <typ:SmtpAddress>eg7636@foo.com</typ:SmtpAddress> </typ:ConnectingSID> </typ:ExchangeImpersonation> </soapenv:Header> <soapenv:Body> <mes:GetInboxRules> <mes:MailboxSmtpAddress>eg7636@foo.com</mes:MailboxSmtpAddress> </mes:GetInboxRules> </soapenv:Body> </soapenv:Envelope> |
这引起了 Microsoft 的成功响应。
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf
我需要一个非常简单的字符串验证器来显示第一个符号与所需格式不对应的位置。我想使用正则表达式,但在这种情况下,我必须找到与表达式相对应的字符串停止的位置,但我找不到可以做到这一点的方法。(这一定是一种相当简单的方法……也许没有?)例如,如果我有正则表达式:/^Q+E+R+$/带字符串:"QQQQEEE2ER"期望的结果应该是7 最佳答案 一个想法:你可以做的是标记你的模式并用可选的嵌套捕获组编写它:^(Q+(E+(R+($)?)?)?)?然后你只需要计算你获得的捕获组的数量就可以知道正则表达式引擎在模式中停止的位置,你可以确定匹配结束
我正在尝试在配备ARMv7处理器的SynologyDS215j上安装ruby2.2.4或2.3.0。我用了optware-ng安装gcc、make、openssl、openssl-dev和zlib。我根据README中的说明安装了rbenv(版本1.0.0-19-g29b4da7)和ruby-build插件。.这些是随optware-ng安装的软件包及其版本binutils-2.25.1-1gcc-5.3.0-6gconv-modules-2.21-3glibc-opt-2.21-4libc-dev-2.21-1libgmp-6.0.0a-1libmpc-1.0.2-1libm
一段时间以来,我一直在使用open_uri下拉ftp路径作为数据源,但突然发现我几乎连续不断地收到“530抱歉,允许的最大客户端数(95)已经连接。”我不确定我的代码是否有问题,或者是否是其他人在访问服务器,不幸的是,我无法真正确定谁有问题。本质上,我正在读取FTPURI:defself.read_uri(uri)beginuri=open(uri).readuri=="Error"?nil:urirescueOpenURI::HTTPErrornilendend我猜我需要在这里添加一些额外的错误处理代码...我想确保我采取一切预防措施来关闭所有连接,这样我的连接就不是问题所在,但是我
我在思考流量控制的最佳实践。我应该走哪条路?1)不要检查任何东西并让程序失败(更清晰的代码,自然的错误消息):defself.fetch(feed_id)feed=Feed.find(feed_id)feed.fetchend2)通过返回nil静默失败(但是,“CleanCode”说,你永远不应该返回null):defself.fetch(feed_id)returnunlessfeed_idfeed=Feed.find(feed_id)returnunlessfeedfeed.fetchend3)抛出异常(因为不按id查找feed是异常的):defself.fetch(feed_id
我是Ruby的新手。我试过查看在线文档,但没有找到任何有效的方法。我想在以下HTTP请求botget_response()和get()中包含一个用户代理。有人可以指出我正确的方向吗?#PreliminarycheckthatProggitisupcheck=Net::HTTP.get_response(URI.parse(proggit_url))ifcheck.code!="200"puts"ErrorcontactingProggit"returnend#Attempttogetthejsonresponse=Net::HTTP.get(URI.parse(proggit_url)