A man who spat into the face and mouth of a female police officer has been jailed for four months.