headlights on 2007 Dodge Magnum

headlights keep flashing on and off,and when they go off i can be driving and tap the dash board on the driverside and they come back on.sometimes they stay on for along time or i have to keep tapping the dash.

Asked by for the 2007 Dodge Magnum
the connector at the switch probably has a bad connection. inspect it carefullly for any burnt terminals.