POST request using RCurl

后端 未结 5 995
予麋鹿
予麋鹿 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:05

    I just wanted to point out that there must be an issue with passing a raw string via the postForm function. For example, if I use curl from the command line, I get the following:

        $ curl -d "Archbishop Huxley" "http://www.datasciencetoolkit.org/text2people
    [{"gender":"u","first_name":"","title":"archbishop","surnames":"Huxley","start_index":0,"end_index":17,"matched_string":"Archbishop Huxley"}]
    

    and in R I get

    > api <- "http://www.datasciencetoolkit.org/text2people"
    > postForm(api, 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" 
    

    Note that it returns two elements in the JSON string and neither one matches on the start_index or end_index. Is this a problem with encoding or something?

提交回复
热议问题