Would you walk up to a stranger and start petting them?
If you wouldn't walk up to another person and start petting them then you shouldn't walk up to a dog and do the same. When that cute little puppy is soooo wiggly and pulling towards you it's hard to stop yourself from reaching down and ask first but that puppy may be working on pulling and jumping. By you giving attention to that jumping puppy you will be reinforcing the behavior they are working hard to change. That puppy could also not enjoy being touched a certain way and may bite you even though they came up to you very excitedly. There are plenty of reasons to always ask first and no reason to not ask when meeting a strange dog.
When the owner tells you no, understand that there is a good reason for it and you should not be offended. I've had people tell me "I'm really good with dogs." or "Dogs love me." when I tell them not to pet my older dog (She tolerates strangers petting her but she doesn't like it). I have no doubt these people are very nice and love dogs but I also know my pup doesn't care how nice they are and would prefer to be left alone. So, when the owner says no, please do not give them reasons why they should let you pet them.
If the owner says yes, let the dog greet you first and not the other way around. Make sure to never reach out quickly or over the dog's head. Always go under and don't make a lot of eye contact (You are a stranger and this can be seen as aggressive to the dog). If the dog pulls away or becomes stiff that's the time to walk away. Not all dogs will want to be your friend, but don't worry there are plenty of other dogs out there who will be happy to meet you.