Since the OP expressed in interest in Ramanujan's formula, this follows from the fact that the cosine transforms $\hat{F}(k)=\sqrt{2/\pi}\int_0^\infty f(x)\cos kx\,dx$ of $f(x)=e^{-x^2/2}$ and $g(x)=1/\cosh(\sqrt{\pi/2}x)$ are the same functions: $\hat{F}(k)=f(k)$ and $\hat{G}(k)=g(k)$. Substitution of the transform and exchange of the order of integration then gives $$\int_0^\infty f(x)g(\alpha x)\,dx=\int_0^\infty f(x)\hat{G}(\alpha x)\,dx=\int_0^\infty f(x)\left(\sqrt{2/\pi}\int_0^\infty g(y)\cos \alpha xy\,dy\right)\,dx$$ $$=\int_0^\infty f(\alpha y)g(y)\,dy,$$ from which the identity follows, $$\sqrt{\alpha} \int_{0}^{\infty} \frac{e^{-x^2}}{\cosh\alpha x} dx=\sqrt{\beta} \int_{0}^{\infty} \frac{e^{-x^2}}{\cosh\beta x} dx,\;\;\text{if}\;\;\alpha\beta=\pi.$$
Ramanujan gave this result in a letter to Hardy, without proof; Hardy wrote back that he knew of the result and had published it, so perhaps "Hardy's formula" is more justified.