WordPress.org

Make WordPress Core

Opened 7 weeks ago

Last modified 7 weeks ago

#54556 new defect (bug)

It's impossible to get 'location' header on 302 redirect of wp_remote_post

Reported by: saturnix2025 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords: reporter-feedback
Focuses: Cc:

Description

https://wordpress.stackexchange.com/questions/398738/get-returned-url-from-wp-remote-post-if-response-code-is-302

<?php
$payload = array('body' => $payload);
$payload['redirection'] = 0;
$response = wp_remote_post( $my_url, $payload );
$redirect_to = wp_remote_retrieve_header( $reponse, 'location' );

In the above code, $redirect_to always returns an empty string when $my_url is an URL that returns 302 redirect.

This is unexpected behavior, as $redirect_to should contain the URL $my_url is redirecting us to.

I've tried replacing "location" with "Location" and "0" with "false" to no avail.

Change History (2)

#1 follow-up: @costdev
7 weeks ago

  • Keywords reporter-feedback added

Hi @saturnix2025, thanks for opening this ticket and welcome to Trac!

Trac is for reporting issues with WordPress Core - so let's see if that's where this issue lies.

  • What version of WordPress are you using?
  • What is the output of var_dump( $response );?

#2 in reply to: ↑ 1 @saturnix2025
7 weeks ago

Replying to costdev:

Hi @saturnix2025, thanks for opening this ticket and welcome to Trac!

Trac is for reporting issues with WordPress Core - so let's see if that's where this issue lies.

  • What version of WordPress are you using?
  • What is the output of var_dump( $response );?

Unfortunately I don't know, as this is shared hosting with no access to a dev console.

Version is 5.8.2

Last edited 7 weeks ago by saturnix2025 (previous) (diff)
Note: See TracTickets for help on using tickets.