Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp_remote_post Content-Type header not respected #1428

Open
key88sf opened this issue May 18, 2024 · 1 comment
Open

wp_remote_post Content-Type header not respected #1428

key88sf opened this issue May 18, 2024 · 1 comment
Labels
[Priority] Medium [Type] Bug An existing feature does not function as intended
Milestone

Comments

@key88sf
Copy link

key88sf commented May 18, 2024

My plugin uses wp_remote_post with a Content-Type: application/json header (see below for code sample). While it works fine in regular WordPress installs, when this code runs in Playground, the Content-Type header is not respected, and instead gets sent as application/x-www-form-urlencoded. This causes my wp_remote_post() call to fail since the server returns an error.

Example of wp_remote_post() call with content-type header:

    $response = wp_remote_post(
      $this->base_url . '/images',
      array(
        'headers'       => array(
          'Content-Type'  => 'application/json',  /* THIS IS NOT BEING RESPECTED by Playground */
          'X-Api-Key'     => $this->api_key
        ),
        'body'          => wp_json_encode( $body )
      )
    );

I confirmed this same exact request to the server endpoint with the proper content-type header works as expected.

The Chrome network tab confirms playground is sending Content-Type: application/x-www-form-urlencoded:
Screenshot 2024-05-18 at 1 12 44 PM

My blueprint file DOES include networking, etc:

  "phpExtensionBundles": [
    "kitchen-sink"
  ],
  "features": {
    "networking": true
  },

Any ideas if it is possible to fix this?

@bgrgicak bgrgicak added this to the PHP Feature Parity milestone May 20, 2024
@bgrgicak bgrgicak added [Type] Bug An existing feature does not function as intended [Priority] Medium labels May 20, 2024
@adamziel
Copy link
Collaborator

adamziel commented May 20, 2024

Let’s:

  • see if that header can be supported
  • log a clear error message if anything about a PHP request cannot be translated into a fetch() call

Also, I’m re-categorizing this as a crash since it’s an error in a basic WordPress feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Priority] Medium [Type] Bug An existing feature does not function as intended
Projects
Status: No status
Development

No branches or pull requests

3 participants