Jump to content

Recommended Posts

Posted

Hi everyone! I'm having troubles developing an API...

$http = $this->wire(new WireHttp());
$http->get("my.example.com");
db($http->getResponseHeaders());

This returns the following:

array
'date' => 'Sat, 22 Oct 2022 18:27:02 GMT'
'server' => 'Apache'
'location' => 'https://my.example.com/'
'content-length' => '238'
'content-type' => 'text/html; charset=iso-8859-1'

my.example.com is setup to redirect from HTTP to HTTPS via 301

$http->getHttpCode()

Returns

  • 301 for ->get("my.example.com")
  • 301 for ->get("http://my.example.com")
  • 0 for ->get("https://my.example.com")

I'd expect it to return 200 for HTTPS, or am I missing something?

Thx!

Posted

Might be from an unsuccessful curl request (stuff like incompatible cipher suites, untrusted certificate etc.). Have you checked $http->getError()?

  • Like 2
Posted

Interesting... It works for www.baumrock.com but not for test2.gemeindeguru.at

$http = $this->wire(new WireHttp());
$http->get("www.baumrock.com");
db($http->getResponseHeaders());
db($http->getHttpCode());
$http->get("test2.gemeindeguru.at");
db($http->getResponseHeaders());
db($http->getHttpCode());

Ha36iks.png

any ideas?

Posted

Sorry, checked getErrors() instead of getError() so I thought that did not help! Here is the error:

2: fsockopen(): php_network_getaddresses: getaddrinfo for  failed: Name or service not known, 2: fsockopen(): Unable to connect to :80 (php_network_getaddresses: getaddrinfo for  failed: Name or service not known), 0: php_network_getaddresses: getaddrinfo for  failed: Name or service not known

What does that mean?

Posted

A bit of a stab in the dark, but maybe an IPV6 issue? I can see that the test2 host has an IPV6 address while the other does not.

Posted

Not at a computer right now, but the error should have the host name in it (where the two spaces collide instead, and before the :80 port). Apparently something went wrong inside wireHttp->get() where it parses the url string. Indeed, url_parse() doesn’t return the right components when given "test2.gemeindeguru.at". I think you’re required to pass the url including the protocol.

  • Like 1
Posted

I think the problem is here https://github.com/processwire/processwire/blob/924f93214536a506babbce1bab5c6c9e2093fc1e/wire/core/WireHttp.php#L471

See how it sanitizes the url at the top of the function. That’s where it prepends the scheme if necessary. Curl and fopen are called with that sanitized url, but your error came from the "socket" method, which seems to be called with the unsanitized url. I’m probably missing something, but I’m not going to look into this any more deeply from my phone ?

  • Like 1
  • Thanks 1
  • bernhard changed the title to WireHttp getHttpCode wrong?
Posted

Hey guys thx for your help. I've changed the line in question to $url and now I get this:

YpFVqiy.png

The certificate is a letsencrypt wildcard cert. I'm totally blank on that topic - is there anything I can do about that? Or is it an issue with WireHttp?

Posted

Update: I tried using Guzzle and also get an error. My research shows that it seems to be a server setup issue! I'll keep you posted - thx for your help so far!

  • 2 months later...
Posted

Today I had to renew the certificate. Unfortunately that can't be done automatically as the challenge relies on DNS records that have to be created. But it's not a lot of work and only has to be done every 3 months, so it's fine.

When renewing the cert I realised that the CA Authority was not properly setup. Now with the new cert everything is green and I get the correct status-code ? 

XNwdYzB.png

Thx for your help!

  • bernhard changed the title to [solved] WireHttp getHttpCode wrong?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...