POST request using RCurl

后端 未结 5 984
予麋鹿
予麋鹿 2020-12-01 10:01

As a way of exploring how to make a package in R for the Denver RUG, I decided that it would be a fun little project to write an R wrapper around the datasciencetoolkit API.

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 10:26

    Generally, in those cases where you're trying to POST something that isn't keyed, you can just assign a dummy key to that value. For example:

    > postForm("http://www.datasciencetoolkit.org/text2people", a="Archbishop Huxley")
    [1] "[{\"gender\":\"u\",\"first_name\":\"\",\"title\":\"archbishop\",\"surnames\":\"Huxley\",\"start_index\":44,\"end_index\":61,\"matched_string\":\"Archbishop Huxley\"},{\"gender\":\"u\",\"first_name\":\"\",\"title\":\"archbishop\",\"surnames\":\"Huxley\",\"start_index\":88,\"end_index\":105,\"matched_string\":\"Archbishop Huxley\"}]"
    attr(,"Content-Type")
                    charset 
    "text/html"     "utf-8" 
    

    Would work the same if I'd used b="Archbishop Huxley", etc.

    Enjoy RCurl - it's probably my favorite R package. If you get adventurous, upgrading to ~ libcurl 7.21 exposes some new methods via curl (including SMTP, etc.).

提交回复
热议问题