I disagree:
Don't be friend's with anyone. Never give into their demands. Unless they are gonna take your city in the next turn, don't ever ever ever give into their demands.
They will ask for any good tech you get, and pretty much any GP you get. This just means you're better off than them. Just defend soundly, expand a lot, and you'll be ok.
There is something to point out though, if they just straight up declare war on you instead of demanding something, they probably just know that you don't have many units in your cities. If this is the case, be extra sure to create defenders. This is the only time when the AI really thinks it has an advantage over you, otherwise most of the time when it's demanding something, it just means you've got something they don't.
It's often beneficial to be at war with them, especially if you are winning in tech and in democracy, then it's to your advantage to always be at war so you can attack while still reaping the benefits of democracy.
You should be the one demanding peace, and that ususally is when you want them off your squares, or if you want to raise some gold by selling them some tech. Other than that, be at war with them, who cares. Just defend well, choke them out of the map, and you'll be fine. You'll learn more by being at war all the time and being pressed than you will by giving things to the AI, or just being peaceful.
Online, even if you are at peace with another player, that doesn't mean anything, at the drop of a hat, the human player will declare war. You don't need allies in this game, you just need to make life hard for the other players.