zachfeldman / rubypress

Ruby interface for the WordPress XMLRPC API. Follows standard XML-RPC Documentation closely.
201 stars 55 forks source link

https 301 redirect problem #61

Closed rickygu closed 5 years ago

rickygu commented 5 years ago
@wordpress = Rubypress::Client.new(:host => ENV['WOO_URL'].split('//').last,
                           :username => ENV['WOO_USERNAME'],
                           :password => ENV['WOO_PASSWORD'],
                           :use_ssl => true,
                           :debug => true)

=> #<Rubypress::Client:0x007f84f33e3bc0 @port=80, @ssl_port=443, @use_ssl=true, @host="website.com", @path="/xmlrpc.php", @username="xxxxx", @password="xxxxx", @default_post_fields=["post", "terms", "custom_fields"], @debug=true, @http_user=nil, @http_password=nil, @retry_timeouts=false, @timeout=30, @cookie=nil> 

> @wordpress.getOptions
opening connection to website.com:443...
opened
starting SSL for website.com:443...
SSL established
<- "POST /xmlrpc.php HTTP/1.1\r\nUser-Agent: XMLRPC::Client (Ruby 2.3.3)\r\nContent-Type: text/xml; charset=utf-8\r\nContent-Length: 304\r\nConnection: keep-alive\r\nAccept-Encoding: identity\r\nAccept: */*\r\nHost: easternspree.com\r\n\r\n"
<- "<?xml version=\"1.0\" ?><methodCall><methodName>wp.getOptions</methodName><params><param><value><array><data><value><i4>0</i4></value><value><string>xxxxx</string></value><value><string>xxxxxx</string></value><value><array><data/></array></value></data></array></value></param></params></methodCall>\n"
-> "HTTP/1.1 301 Moved Permanently\r\n"
-> "Date: Sat, 29 Dec 2018 04:57:25 GMT\r\n"
-> "Server: Apache/2.4.29 (Ubuntu)\r\n"
-> "Location: https://website.com/\r\n"
-> "Content-Length: 316\r\n"
-> "Keep-Alive: timeout=5, max=100\r\n"
-> "Connection: Keep-Alive\r\n"
-> "Content-Type: text/html; charset=iso-8859-1\r\n"
-> "\r\n"
reading 316 bytes...
-> "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>301 Moved Permanently</title>\n</head><body>\n<h1>Moved Permanently</h1>\n<p>The document has moved <a href=\"https://website.com/\">here</a>.</p>\n<hr>\n<address>Apache/2.4.29 (Ubuntu) Server at website.com Port 443</address>\n</body></html>\n"
read 316 bytes
Conn keep-alive
RuntimeError: HTTP-Error: 301 Moved Permanently
    from (irb):138

It seems like the request is going to http://website.com and not https://website.com, which is getting redirected to https://website.com. It seems like others had similar problems and they were able to solve it by including https:// in the url, but adding https:// in the host setting will result in invalid URL.

zachfeldman commented 5 years ago

@rickygu I'm not sure that https is automatically added to the URL if SSL is specified. What happens if you put HTTPs in the URL?

rickygu commented 5 years ago

doesn't allow me to put https directly in the url without error.

zachfeldman commented 5 years ago

Without knowing the URL you're trying to connect to, it's almost impossible to say what the issue might be. But are you sure that at this URL there's an xmlrpc.php file publicly accessible? Considering nobody else has reported this issue I'm inclined to think it's a problem with the server you're trying to send requests to. To narrow it down, maybe try with a different WordPress installation somewhere. Sorry, that's the best I can do for you!