Я пытаюсь создать запрос POST, но параметр body работает не так, как я ожидал.
Запрос POST_bodyRequest. xml file
<?xml version="1.0" encoding="UTF-8"?>
<rs:alarm-request throttlesize="0"
xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
<rs:requested-attribute id="0x10000"/>
<rs:requested-attribute id="0x10001"/>
<rs:requested-attribute id="0x10009"/>
<rs:requested-attribute id="0x1000a"/>
<rs:requested-attribute id="0x1006e"/>
<rs:requested-attribute id="0x11ee8"/>
</rs:alarm-request>
Код, в основном вызов POST
xml <- upload_file("POST_bodyRequest.xml")
r2 <- POST(url, login.password, body = list(xml))
status_code(r2)
Первое, на что нужно обратить внимание, это то, что содержимое файла не сохраняется в файле "xml":
> xml <- upload_file("POST_bodyRequest.xml")
> xml
Form file: POST_bodyRequest.xml (type: application/xml)
> str(xml)
List of 2
$ path: chr "D:\\MPM\\POST_bodyRequest.xml"
$ type: chr "application/xml"
- attr(*, "class")= chr "form_file"
Следовательно, вызов POST возвращает ошибку
> r2 <- POST(url, login.password, body = list(xml))
Error: All components of body must be named
> status_code(r2)
[1] 415
Я также пытался прочитать файл xml, используя xmlParse () . В этом случае код восстанавливается, как и ожидалось, но я получаю ту же ошибку при вызове POST.
> xml <- xmlParse(file = "POST_bodyRequest.xml")
> r2 <- POST(url, autenticacao, body = list(xml))
Erro: All components of body must be named
> xml
<?xml version="1.0" encoding="UTF-8"?>
<rs:alarm-request xmlns:rs="http://www.ca.com/spectrum/restful/schema/request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throttlesize="0" xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
<rs:requested-attribute id="0x10000"/>
<rs:requested-attribute id="0x10001"/>
<rs:requested-attribute id="0x10009"/>
<rs:requested-attribute id="0x1000a"/>
<rs:requested-attribute id="0x1006e"/>
<rs:requested-attribute id="0x11ee8"/>
</rs:alarm-request>
> str(list(xml))
List of 1
$ :Classes 'XMLInternalDocument', 'XMLAbstractDocument' <externalptr>
> status_code(r2)
[1] 415
У меня не было проблем с запросами GET в R. Запрос POST отлично работает с SoapUI. Итак, что я делаю не так?