Domanda

I want to use the following curl command using RCurl

curl -X POST http://test.reco4j.org:7474/db/data/ext/Reco4jRecommender/node/248/get_recommendations -H "Content-Type: application/json" -d '{"type":"0"}'

so i am using the following R code

library(RCurl)
library(RJSONIO)
postForm("http://test.reco4j.org:7474/db/data/ext/Reco4jRecommender/node/248/get_recommendations",
         .opts = list(postfields = toJSON(list(id = "0")),
                      httpheader = c('Content-Type' = 'application/json', ssl.verifypeer = FALSE)
                      ))

But I get an "Internal server errror", so i am not sure my R code is wrong or it is a windows problem.
The reason I am mentioning this, is that the original curl command fails in windows but works on mac and Linux, so I am not sure the R failure is a windows issue or an R issue.

È stato utile?

Soluzione

You have an error in your code. The pair you need to send is "type":"0" you are sending "id":"0".

library(RCurl)
library(RJSONIO)
res <- postForm("http://test.reco4j.org:7474/db/data/ext/Reco4jRecommender/node/248/get_recommendations",
         .opts = list(postfields = toJSON(list(type = "0")),
                      httpheader = c('Content-Type' = 'application/json', ssl.verifypeer = FALSE)
                      ))
out <- fromJSON(rawToChar(res))

> head(out[[1]])
$outgoing_relationships
[1] "http://test.reco4j.org:7474/db/data/node/2285/relationships/out"

$data
$data$movieId
[1] 1342

$data$title
[1] "Convent, The (Convento, O) (1995)"

$data$releaseDate
[1] "14-Jun-1996"

Altri suggerimenti

It looks like a bad URL. I get an HTTP ERROR 500: INTERNAL_SERVER_ERROR trying to access that URL in firefox.

EDIT: Disregard, you're right: the curl command worked in a shell prompt. Sorry for doubting you.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top