How to send data to a Wordpress post or page from r

时间:2018-12-03 13:18:03

标签: r wordpress httr

So I'm in a bit over my head here. I can GET information from my Wordpress site using httr:

For instance, to get the details of post ID 141, I use this:

ws = GET("https://example.com/wp-json/wp/v2/posts/141")

Works fine because the authentication is through cookies I think, and I'm logged into my Wordpress site.

But I can't POST to my wordpress site because (I think) the cookie-type authorization is not allowed.

So this returns a 401 error:

POST ('example.com/wp-json/wp/v2/posts/141',
                  body = list(title = "My New Title"))

I think I need to send an authorization header, but I'm not sure how to set that up.

0 个答案:

没有答案