Tag Info

Hot answers tagged

6

Less than an answer, but just a list of things straight from my experience with it - maybe you've overlooked something. Debugging the request & its results Without diggin' too deep into the update process, but the WP HTTP API uses the WP_HTTP class. It also offers a nice thing: A debug hook. do_action( 'http_api_debug', $response, 'response', $class, ...


6

Here is some quick first draft code for populating a dropdown from the Google Font API, I do not know about the options framework so this will not deal with that. 1. Get an API Access Key from Google Your request will need a valid key, you can follow the instruction here on how to get one: https://developers.google.com/webfonts/docs/developer_api It's ...


6

Check out download_url() - it's only loaded in the admin, so you'll have to include it (or write your own) if needed on the front-end. From download_url() you can use: $response = wp_remote_get( TCS_CPDF_REMOTE_ZIP, array( 'timeout' => 300, 'stream' => true, 'filename' => TCS_CPDF_LOCAL_ZIP ) );


5

Lots of places in WordPress use xml_parse including the Atom library, the XML-RPC Library that we use, and SimplePie The oembed class uses SimpleXML. The WordPress Importer and Jetpack actually use both (Jetpack for different things, and the importer tries to use SimpleXML and falls back if it doesn't exist). Basically, there's nothing built into ...


5

According to this ticket: Cannot serialize object wrapping 3rd party library structs. Must serialize the xml (to a string) and store that to session and reload the xml when restoring from session When you are storing object in transient it gets serialized and not all objects are capable of that correctly. Store textual XML data in transient ...


4

Quite an edge case, but the accepted encoding types should be filterable nonetheless. I can see a few situations where fine, granular control over this header would be useful (as in adding an API that uses non-standard encoding). So, while there's no stock hook for this, I have created a Trac ticket for it and submitted a patch. If you voice support on ...


4

If you take a look at WP_HTTP->request() (which all related functions wrap) it provides a filter hook for the purpose of overriding making a request in favor of returning arbitrary data as response: // Allow plugins to short-circuit the request $pre = apply_filters( 'pre_http_request', false, $r, $url ); if ( false !== $pre ) return $pre;


3

I figured it out. The WordPress HTTP API was doing it's job; my problem was with the API I was working with. I just modified my code like: $url = 'https://www.testurl.com'; $xml = <<<TESTED XML HERE>>>; $response = wp_remote_post( $url, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => ...


3

Based on @kaiser’s useful answer I have written some code that seems to work well. That is the reason why I marked it as The Answer. Let me explain my solution … The logic When a request it sent through the API is runs through WP_Http::request(). That’s the method with … @todo Refactor this code. … in its header. I couldn’t agree more. Now, there ...


3

The proxy settings work just like a regular HTTP requests but in this case obviously routed through a proxy. In terms of WordPress the API's transport layers all support proxy connections(fsockopen, fopen, cURL, ). The things about proxy configurations are they come in several flavors and each setup is different so it makes answering this difficult, it ...


3

Update & the internal WP HTTP API A slightly modified version of my answer to this question, but also as a plugin that shows how it could work. Note: The code is not tested - I don't know your server setup, etc. - and just written out of my head. You'll have to test it, find the proper position for merging the arguments and set your URL, etc. The ...


3

As a general note, there's the http-api (you've already used it to tag your question) that has an archive. WP HTTP API Here's a list of "How to"-answers about the HTTP API basics chose the right protocol filter the request uri/url. download a file from a remote location deactivate HTTP requests Post Data Yes, you just use wp_insert_post() and similar ...


2

PHP allows you to send header information using the header() command. More specific to WordPress is the send_headers action hook. Also: always remember that you have to send all your headers before any output is sent to the screen.


2

The best way to check the referrer will depends of what are you trying to do. You can use wp_get_referer() or wp_get_original_referer(), but if you want to check the referer for security reasons you should definitely use other functions like check_admin_referer(), check_ajax_referer(), wp_referer_field() or other of the Wordpress Nonces related functions.


2

There is no filter named "http_response_timeout" in the WordPress core. Where are you finding this filter name from? The timeout parameter as passed to a wp_remote call has a default of five seconds, and that default can be changed using the "http_request_timeout" filter, which is a different name than you used. Maybe you're just using the wrong word?


2

In order to isolate your code further, I would wrap the wp_remote_get etc calls in an interface with two implementations. One implementation calls wp_remote_get, and the other returns test data. Using a tool such as runkit in this situation sidesteps the actual problem you have, which is that your code and the APIs are too tightly coupled, and a level of ...


2

Short answer: No, there's no hook for that. Long answer: You could possibly submit a patch at WordPress Trac, if you really need to adjust this option. Personally, I didn't ever had problemes with WP_Http_Encoding::accept_encoding() and the question you mentioned could be answered by manually gzinflate() the response. IMHO, this seems to be the only ...


2

So far as I know, it's available to use. Your site already hits it a few times each day for plugin updates, theme updates, etc. It's not really well-documented, though ... so when you start building your code, please document what calls you're using and how you're using them in the Codex so everyone else can benefit.


2

There is very little documentation, the link in EAMann's comment is the best I have seen. To grab plugin specific data you can use the following url and it will return XML with a lot of info. http://api.wordpress.org/plugins/info/1.0/plugin-name.xml For example: http://api.wordpress.org/plugins/info/1.0/akismet.xml


1

Ad Timeout You should be able to get around the timeout using a filter add_filter( 'http_request_timeout', 'wpse35826_timeout_extd' ); function wpse35826_timeout_extd( $time ) { // Default timeout is 5 return 10; } Choose the right protocol/scheme About your protocol/scheme problem: If it's your local install, you can use the conditional. ...


1

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 ...


1

This doesn't seem to be error coming from WP itself, but is likely generated by curl, which WP likes to pick first for network requests. I'd try to replicate request with curl by hand on your hosting and elsewhere. If you are content with doing network request in other way you can tweak to make WP skip curl as transport and go for other options.


1

In one (two) word(s): Mock Data. PHPUnit got getMock() available exactly for that. As the other answers already have perfectly summoned… where to get valid mock data (Otto) - make sure you occasionally fetch fresh data and where to intercept the data (Rarst) and what tools to use (TomJNowell) …there only (might be) the issue left that your ...


1

Since I want to easily review the http returns together with the logfiles I log them in a request database. during development handy since i have a second database that stores the metadata of the physical cache. so when i delete that one (over and over again). I can keep on doing requests from the request database and will not bother external servers time ...


1

If this file is remotely available to you, then you should be using the HTTP API. $response = wp_remote_request( 'http://xml.prisguide.no/productExport.php?productId=151690' ,array( 'ssl_verify' => true // If the request isn't working, try it with `false` ) ); You then simply go and catch the response and check if it's an error: ...


1

AFAIK URL encoding the cookie value is still kind of a defacto standard, it's an ancient relict based on the old, ugly Netscape cookie specs, that basically says that semicolons, commas and whitespaces are disallowed, and should be encoded, for example using URL encoding. Neither does it does it require enocding, nor does it force the use or URL encoding, ...


1

add_filter('http_request_args', 'http_request_args_custom', 10,2); function http_request_args_custom($request,$url){ if (strpos($url, 'wordpress.org') !== false){ global $replaced_url; $replaced_url = 'http://wordpress.local'; } return $request; } ...



Only top voted, non community-wiki answers of a minimum length are eligible