Frage

I'm trying to get the following HTTP POST containing XML to work using RCurl package in R:

curl -X POST 'https://api.example.com/resource.xml' -d 'From=value' 
-d 'To=value' -d    'Body=value' -u username:password

I have no problems running the above code using command line, but when I try to use postForm in the RCurl package, I run into problems.

Here is my attempt using postForm in RCurl:

postForm('https://api.example.com/resource.xml',
userpwd="username:password",From='value',To='value',Body='value')

It seems supplying the username/password is the main issue. I can pass the params without an issue.

War es hilfreich?

Lösung

You are specifying the userpwd argument incorrectly. Try:

postForm('https://api.example.com/resource.xml',
         From='value',
         To='value',
         Body='value',
         .opts=list(userpwd="username:password"))

Note: RCurl syntax is kind of idiosyncratic, so in postForm the ... argument refers to HTTP headers whereas in getURL (from your previous question), the ... argument refers to curl options. This is probably what is tripping you up.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top