使用RCurl CurlPerform访问Web服务:获取HTTP 500错误

时间:2017-07-25 17:04:05

标签: r web-services rcurl http-status-code-500

我正在尝试使用RCurl包的web服务。

此网络服务' https://ngcsi.contigohosting.com/Entrader_Dev/wcfservices/TradingService.svc'有很多get方法只能通过

访问

身份验证,因此我在标头中传递用户名和密码。

h=basicTextGatherer()
headerFields =
    c(c(Accept="text/xml", Accept="multipart/*",
        'Content-Type' = "text/xml; charset=utf-8"),
      SOAPAction = "https://ngcsi.contigohosting.com/Entrader_Dev/wcfservices/TradingService.svc?wsdl")

body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 

xmlns:con="http://entrader.contigoenergy.com/Contigo.Entrader.Service">\
    <soapenv:Header>\
<wsse:Security soapenv:mustUnderstand="1"\
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">\
<wsse:UsernameToken wsu:Id="UsernameToken-37"\
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">\
<wsse:Username>Username</wsse:Username>\
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>\
</wsse:UsernameToken>\
</wsse:Security>\
</soapenv:Header>\
<soapenv:Body>\
</soapenv:Body>\
</soapenv:Envelope>\n'

curlPerform(url = "https://ngcsi.contigohosting.com/Entrader_Dev/wcfservices/TradingService.svc",
            httpheader = headerFields,
            postfields = body, 
            writefunction = h$update,
            verbose=TRUE
)

body=h$value()

执行上面和下面的操作时出现HTTP / 1.1 500内部服务器错误是正文内容

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2017-07-25T15:14:00.856Z</u:Created><u:Expires>2017-07-25T15:19:00.856Z</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-GB">The message with Action 'https://ngcsi.contigohosting.com/Entrader_Dev/wcfservices/TradingService.svc?wsdl' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring></s:Fault></s:Body></s:Envelope>

非常感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

SOAPAction应该有一个方法,在这个实例中可以是上面使用的wsdl中的任何一个。

http://entrader.contigoenergy.com/Contigo.Entrader.Service/TradingService/GetTrade

http://entrader.contigoenergy.com/Contigo.Entrader.Service/TradingService/GetByFilterTrade

因此,新代码应如下所示

h=basicTextGatherer()
headerFields =
    c(c(Accept="text/xml", Accept="multipart/*",
        'Content-Type' = "text/xml; charset=utf-8"),
      SOAPAction = "http://entrader.contigoenergy.com/Contigo.Entrader.Service/TradingService/GetTrade")

body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 

xmlns:con="http://entrader.contigoenergy.com/Contigo.Entrader.Service">\
    <soapenv:Header>\
<wsse:Security soapenv:mustUnderstand="1"\
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">\
<wsse:UsernameToken wsu:Id="UsernameToken-37"\
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">\
<wsse:Username>Username</wsse:Username>\
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>\
</wsse:UsernameToken>\
</wsse:Security>\
</soapenv:Header>\
<soapenv:Body>\
</soapenv:Body>\
</soapenv:Envelope>\n'

curlPerform(url = "https://ngcsi.contigohosting.com/Entrader_Dev/wcfservices/TradingService.svc",
            httpheader = headerFields,
            postfields = body, 
            writefunction = h$update,
            verbose=TRUE
)

body=h$value()

以上代码有效,我可以从网络服务获得适当的响应,尽管我在上述示例中没有提到任何内容。