我正在尝试建立肥皂请求以登录波兰语REGON API。我尝试了很多在Internet上找到的方法,但没有一个起作用。基于API的手动登录请求具有这样的xml结构:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/PUBL/2014/07">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj</wsa:Action>
<wsa:To>https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc</wsa:To>
</soap:Header>
<soap:Body>
<ns:Zaloguj>
<!--Optional:-->
<ns:pKluczUzytkownika>user_key</ns:pKluczUzytkownika>
</ns:Zaloguj>
</soap:Body>
</soap:Envelope>
然后,我尝试将其传递给soupUI,但它对我不起作用。使用soapUI时对我有用的XML代码是:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://CIS/BIR/PUBL/2014/07">
<soap:Header>
<To soap:mustUnderstand="1" xmlns="http://www.w3.org/2005/08/addressing">https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc</To>
</soap:Header>
<soap:Body>
<ns:Zaloguj>
<!--Optional:-->
<ns:pKluczUzytkownika>user_key</ns:pKluczUzytkownika>
</ns:Zaloguj>
</soap:Body>
</soap:Envelope>
标题:
POST https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj"
Content-Length: 606
Host: wyszukiwarkaregon.stat.gov.pl
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
这是我尝试过的R代码:
test <- httr::POST(url = "https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc",
body = upload_file("request_login.xml"),
httr::add_headers(c('Accept-Encoding' = 'gzip,deflate',
'Content-Type' = 'application/soap+xml;charset=UTF-8;action="http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj"',
'Host' = 'wyszukiwarkaregon.stat.gov.pl',
'Connection' = 'Keep-Alive')))
其中request_login.xml包含传递到soupUI的xml代码。它返回http状态500
第二种方法是:
reader <- basicTextGatherer()
reader$reset()
curlPerform(url = "https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc",
httpheader=c("Accept-Encoding" = "gzip,deflate",
"Content-Type" = 'application/soap+xml;charset=UTF-8,action="http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl/Zaloguj"'),
postfields = toJSON(list("pKluczUzytkownika" = "user_key")),
customrequest = "POST",
writefunction = reader$update,
verbose = T,
ssl.verifypeer = FALSE)
reader$value()
此代码返回html状态415。
我需要R中的解决方案,与什么软件包无关。