Change the headers content type with wp_remote_post

Working with the remote API requests with WordPress. I have used wp_remote_post() function to request the HTTP data but I am unable to update the headers Content-type I am using the following code

 wp_remote_post( $url, array(
    'method' => 'POST',
    'timeout' => 45,
    'redirection' => 5,
    'httpversion' => '1.0',
    'blocking' => true,
    'headers' => array("Content-type" => "application/x-www-form-urlencoded;charset=UTF-8"),
    'body' => array( 'username' => 'bob', 'password' => '1234xyz' ),
    'cookies' => array()
    )
);

But when I print the response content-type is still text/html but the server require urlencoded content-type.
How i can update the headers content type?

1 Answer
1

So, you set the headers of a request using wp_remote_post() and you expect that headers be used in the response. That is what I understand from you:

When I print the response content-type is still "text/html"

I think that you are missunderstanding the HTTP headers. Using wp_remote_post() you make a request and you can set the headers of the request to whatever you need but obviously you can not control the headers of the response.

The headers of the response depends absolutely in the remote server.

Leave a Comment