且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用RCurl登录WordPress

更新时间:2023-12-02 09:11:40

使用REDCap处理了类似的东西 - 也可能对你有用。这个简短的例子显示了我如何使用REDCap API来抓取数据。

I've dealt with something similar using REDCap - might be useful for you too. This short example shows how I used the REDCap API to grab data.

library(RCurl)
out <- postForm("https://redcap.url.org/redcap/api/",
                 token="INSERT TOKEN HERE",
                 content="record",
                 type="flat",
                 format="csv",
                 .opts=curlOptions(ssl.verifypeer=FALSE))
write(out,file="C:/wherever/out.csv")

请注意,这不适合检查SSL - 我已在以后的版本中改进。我的Google+个人资料中的解释更为冗长: https://plus.google.com/106259574970597769926/posts / U3fVCTV4EdQ

Note that this doesn't do proper checking for SSL - I've improved that in later versions. The more lengthy explanation is on my Google+ profile: https://plus.google.com/106259574970597769926/posts/U3fVCTV4EdQ

看起来你可以使用cURL通过传递正确的参数来登录Wordpress,如下所示:
http://w4dev.com/wp/login-into-wp-using-curl/ a>

It looks like you can use cURL to log into Wordpress by passing the right parameters, as described here: http://w4dev.com/wp/login-into-wp-using-curl/

问题的网址似乎是 http://localhost/wordpress/wp-login.php 并且可以在上面的页面找到重要的参数。基本上,您需要定义用户,他们的密码,以及您想要将它们重定向到网站上的位置。这些是如何在PHP示例中描述的参数

It looks like the URL in question is http://localhost/wordpress/wp-login.php and the parameters that matter can be found at the page above. Basically, you need to define the user, their password, and where you want to redirect them to on the site afterwards. These are how the parameters are described in that PHP example

"log=". $login_user .
"&pwd=" . $login_pass .
"&wp-submit=Log%20In&redirect_to=" . $visit_url;

基本上,它只是构造一个字符串来发布,看起来像:

Basically, it's just constructing a string to post, which looks something like:

http://yourwordpress.fake/wp-login.php?log=trehman&pwd=abc123456&wp-submit=Log%20In&redirect_to=http://yourwordpress.fake/pageyouwant

因此,您只需更改上面的postForm即可不同的URL和参数,它应该让你认证,然后重定向到你想要的页面。我不是这里的专家,但我确定您可以重定向到另一个带有参数的长网址,这将允许您提交表单或类似的东西。

So, you could just change the postForm above to have a different URL and parameters, and it should get you authenticated and then redirect you to the page you want. I'm not an expert here, but I'm pretty sure that you can redirect to another long URL with parameters, which would let you "submit" a form or something similar.