It depends on what kind of harrassment you are talking about. If they are whistling or howling from the side of the road but pose no physical threat to you, just smile and accept the "praise" graciously but keep walking. Some men are clueless. They don't see their actions as predatory. If some creep is right in your personal space and making you uncomfortable, assess your situation quickly. Look for an escape route first, then kindly tell the person you are not interested, or that you are in a rush to get some place and put as much distance between him and you as you can.
The most important thing is to always be aware of your surroundings. You don't have to think of every man as a predator lurking around the corner, but sometimes you can tell which types will be trouble from a distance and you can plan a route to avoid confrontation.