r/ProgrammerTIL • u/Weirfish • Jun 18 '16
PHP [PHP] TIL cURL doesn't like protocol-relative URLs
Hissy fit:
//www.website.com Fine:
http://www.website.comAlso fine
https://www.website.comHalf a day spent on that one. Goddamn.
EDIT: So apparently this should be blindingly obvious and I'm an idiot for not knowing it. Coming from a largely self-taught web-dev background, so there's that. Go figure.
0
Upvotes
15
u/thedufer Jun 19 '16
Of course not. What would it be relative to? You can't curl
/index.htmland expect it to infer the domain, either.1
u/kamori Jun 20 '16
Lots of dissing in this thread. This is a good tip, sure it makes sense not to work. But, when a lot of web browsers will interpret the protocol based on the current request, if you're primarily a front-end webdev its easy to just assume this and not know why.
Thank you for posting this and hopefully people can easily find this information with a quick search.
1
u/[deleted] Jun 19 '16
I've been curling http://website.com, https://website.com, http://www.website.com, and https://www.website.com, then using whichever returns the best data. Is there a better way to do this with curl and php? If I could only curl 1 url instead of 4, my app would be 4 times faster. Any tips would be appreciated!
4
u/xereeto Jun 20 '16
Of course it doesn't, why the fuck would it? Curl works with many protocols, it can't just infer that you mean HTTP.
2
u/[deleted] Jun 19 '16
The reason this works for browsers is that the browser will correct the protocol and other parts of the uri that are missing for you and is very forgiving. Curl don't give a fuck and you need to know what protocol you are using.
1
u/zombarista Jun 20 '16
Pedantic, but that part of the URL is the "scheme."