phpxmlrpc icon indicating copy to clipboard operation
phpxmlrpc copied to clipboard

Unable to follow http to https redirect

Open seowner opened this issue 3 years ago • 3 comments

Hi,

There seems to be a problem where PHPXMLRPC doesn't understand how to accept/decipher an http -> https redirect.

object(PhpXmlRpc\Response)[13] public 'val' => int 0 public 'valType' => null public 'errno' => int 5 public 'errstr' => string 'Didn't receive 200 OK from remote server. (HTTP/1.1 301 Moved Permanently)' (length=74) public 'payload' => null public 'hdrs' => array (size=0) empty

I fixed this in my posting script by adding these two lines:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_POSTREDIR, 7);

So I tried adding these lines in Client.php (near all of the cURL stuff) but it still doesn't work.

Any idea how to make PHPXMLRPC understand that http -> https redirects and valid and should be followed?

seowner avatar Oct 09 '20 07:10 seowner

Hello.

Two things:

a) the Client class has a setCurlOptions method already available. You can use that if you want to inject any custom curl option into your current code, without having to resort to 'hacking' the client

b) the Client does not always use curl out of the box- which might explain why your changes are not taken into account. If you want to make sure that curl is used, add a $client->setUseCurl(Client::USE_CURL_ALWAYS) call

gggeek avatar Oct 10 '20 07:10 gggeek

PS: adding "easy" support for allowing the client to follow redirects is in fact a worthwhile enhancement, and it has been in my todo list for a long time (see list at http://gggeek.github.io/phpxmlrpc/ )... I might create a separate ticket for that

gggeek avatar Oct 10 '20 07:10 gggeek

Hello again. Did you manage to overcome your problem?

gggeek avatar Dec 11 '20 17:12 gggeek

Long time no see :-)

I have tested following redirections, and indeed it was not possible to do so. The code has now been fixed to allow that - the end user will still have to manually set the relevant CURL options though.

This will be in upcoming release 4.9

gggeek avatar Nov 26 '22 15:11 gggeek