2016-11-01 26 views
1

我現在有麻煩了。R中的SOAP請求失敗

我試圖用R進行SOAP數據交換,但始終得到服務器的響應如下:

試圖210.242.163.56 ...

連接到210.242.163.56(210.242.163.56 )端口80(#0)

POST/SendDigXml/HTTP/1.1

主機:210.242.163.56

接受:文/ XML

接受:多/ *

內容類型:文本/ XML的;字符集= UTF-8

的SOAPAction:http://210.242.163.56/SendDigXml/GetLastMod

的Content-Length:397

上傳完全發送關:397出來的397個字節

< HTTP/1.1 500內部服務器錯誤

< Cache-Control:private

< Content-Type:文/ XML;字符集= UTF-8

<服務器:Microsoft-IIS/7.5

< X-ASPNET-版本:4.0.30319

< X供電,通過:ASP.NET

<日期:星期二,2016年11月1日6點32分54秒GMT

<的Content-Length:441

<連接:保持活動

<年齡:0

< 連接#0託管210.242.163.56原封不動

而且faulcode和Faultstring讓人:

<faultcode>soap:Client</faultcode> 
<faultstring>The server could not recognize the value of the HTTP header SOAPAction: http://210.242.163.56/SendDigXml/GetLastMod/.</faultstring> 

我在RCurl包中使用curlPerform函數,並使用以下代碼:

library(RCurl) 
id ="iamuser" 
pw ="letmepass" 

headerFields = 
c(Accept = "text/xml", 
Accept = "multipart/*", 
'Content-Type' = "text/xml; charset=utf-8", 
SOAPAction = "http://210.242.163.56/SendDigXml/GetLastMod") 

body = sprintf('<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
<GetLastMod xmlns="http://210.242.163.56/SendDigXml/"> 
<user_id>%s</user_id> 
<password>%s</password> 
<county_code>%s</county_code> 
<data_type>%s</data_type> 
</GetLastMod> 
</soap:Body></soap:Envelope>',id,pw,"Y","1") 

reader = basicTextGatherer() 

getupdate<-curlPerform(url = "http://210.242.163.56/SendDigXml/", 
        httpheader = headerFields, 
        postfields = body, 
        writefunction = reader$update, 
        verbose = TRUE) 

SOAPAction的值格式是按照模板的規定,並且還嘗試了其他幾種表示法,但結果都是一樣的。我不知道我還能嘗試什麼。有人能幫我嗎?

謝謝你的時間。

回答

0

好的,我發現有什麼問題。

SOAPAction應該是"http://tempuri.org/GetLastMod",而不是"http://210.242.163.56/SendDigXml/GetLastMod"

<GetLastMod xmlns="http://210.242.163.56/SendDigXml/"><GetLastMod xmlns="http://tempuri.org/">

只是在http://210.242.163.56/SendDigXml示例代碼相同。

我認爲這是一個錯誤,任何受過訓練的程序員都不會犯它。但我沒有受過訓練的程序員...我會保留這個問題而不是刪除它。我希望它能幫助像我這樣的人。