Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 202004

R: httr SOAP POST request for xml return error - "media type is unsupported"

$
0
0

I'm trying to use R script to make SOAP query. Expecting xml file response. The POST request return error: 415. I am struggling how to phrase it right in R.

I tried in httr:

library(httr)
library(xml2)
library(RCurl)


headers = "{'content-type': 'text/xml'}"  #Also tried'application/xml; charset=utf-8'}"
body = '<?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>
    <GetGenericData xmlns="http://...">
      <QueryMessage xmlns="http:.../...">
        <Query>
          <DataWhere xmlns="http://.../...">
            <And>
              <DataSet>ABC</DataSet>
              <Dimension id="ABC">abc</Dimension>
            </And>
          </DataWhere>
        </Query>
      </QueryMessage>
    </GetGenericData>
  </soap:Body>
</soap:Envelope>'

#headers <- c('application/xml; charset=utf-8')
#names(headers) <- 'content-type'

response = POST("http://exampleWebService?op=GetGenericData", 
                config = list(add_headers(.headers = headers)) ,
                body = body, 
                content_type(".xml"),
                encode = 'raw',
                accept_xml(),
                type = 'application/soap+xml; charset=utf-8',
                # content_type_xml(),
                authenticate(":", ":", "ntlm"))
                )

Then the query response status would be error:

> response[["all_headers"]][[1]]
$status
[1] 401

> response[["all_headers"]][[2]]
$status
[1] 415

>content(response)

No encoding supplied: defaulting to UTF-8.
{xml_document}
<html>
[1] <body><p>The server cannot service the request because the media type is unsupported.</p></body>

What would be the right header/encoding/content-type??? Any hint?



Viewing all articles
Browse latest Browse all 202004

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>