最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

http api - POST to a REST API from a wordpress form

programmeradmin0浏览0评论

I dont want to use a REST API to publish to wordpress.

I want to create a form on a wordpress page which will send a POST to an external REST API. Users will put in their information, and perhaps upload a file. When the press "submit" I want this information to be sent to a REST API on a different server (not wordpress).

Are there any plugins that allow this? Has anyone done this? Of course, I might run into troubles with this:

It looks like I want to do the reverse of this: / Instead of making a REST API for wordpress, I want to make wordpress communicate send a POST to an external REST API when a user presses a button on a form.

I dont want to use a REST API to publish to wordpress.

I want to create a form on a wordpress page which will send a POST to an external REST API. Users will put in their information, and perhaps upload a file. When the press "submit" I want this information to be sent to a REST API on a different server (not wordpress).

Are there any plugins that allow this? Has anyone done this? Of course, I might run into troubles with this: http://en.wikipedia/wiki/Same_origin_policy

It looks like I want to do the reverse of this: http://wordpress/extend/plugins/json-api/ Instead of making a REST API for wordpress, I want to make wordpress communicate send a POST to an external REST API when a user presses a button on a form.

Share Improve this question asked Apr 14, 2012 at 17:31 TimOTimO 311 gold badge1 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

I don't know of a plugin that does it in a general way; for the most part, you'll need to build something custom for each specific API you intend to communicate with.

For your purposes, the key function will be wp_remote_post(), which is a wrapper for the POST method of WP's HTTP class. (Use this instead of making manual cURL requests, because WP_Http has all kinds of fallbacks for different modes of HTTP transport.) Here's a nice introduction: http://yoast/wp-best-practice/wordpress-http-api/ Same origin policies generally only apply to browsers. wp_remote_post() and its ilk are fired on the server.

Sending data is pretty easy - just put an array into the 'body' of your wp_remote_post() call. The tricky part is always authentication - does the API server expect a pre-registered key, or some sort of oAuth handoff, or what. If it's as simple as a shared key, you can just pass it as part of the 'body' payload.

发布评论

评论列表(0)

  1. 暂无评论