Every person imprisoned or restrained of the person's liberty under any pretense whatever may prosecute a writ of habeas corpus to inquire into the cause of such imprisonment or restraint and thereby, except in the cases specified in section 32-22-02, obtain relief from such imprisonment or restraint if it is unlawful.
N.D.C.C. § 32-22-01