I am trying to evaluate the integral. $$\int_0^\infty \frac{x^{p-1}}{1+x^{2}} \, dx$$ where $0<p<2$ and $p \neq 1$, the answer says the integral should be $\frac{2}{\pi}\csc (\frac{\pi p}{2})$
I got an answer up to $\frac{\pi ((i)^{p-1}+{-i}^{p-1})}{1-exp(2\pi i (p-1))}$, not sure how to proceed from this or if this is even right.


By cutting the plane along the positive real axis, the pole at $z=i=e^{i\pi/2}$ while the pole at $z=-i=e^{i3\pi/2}$.
Then, we have $i^{p-1}=e^{i(p-1)\pi/2}$ and $(-i)^{p-1}=e^{i3(p-1)\pi/2}$.
Therefore, $2\pi i$ times the sum of the residues is
$$2\pi i\left(\frac{e^{i(p-1)\pi/2}}{2i}+\frac{e^{i3(p-1)\pi/2}}{-2i}\right)=-2\pi i e^{i(p-1)\pi}\sin(\pi(p-1)/2)$$
Finally, we have
$$\begin{align} \int_{0}^\infty\frac{x^{p-1}}{1+x^2}\,dx&=\frac{-2\pi i e^{i(p-1)\pi \sin((p-1)\pi/2)}}{1-e^{i2\pi(p-1)}}\\\\&=\frac{-2\pi i e^{i(p-1)\pi \sin((p-1)\pi/2)}}{-e^{i(p-1)\pi}(e^{i(p-1)\pi}-e^{-i(p-1)\pi})}\\\\ &=\pi\frac{\sin((p-1)\pi/2)}{\sin((p-1)\pi)}\\\\ &=\frac\pi{2\cos((p-1)\pi/2)}\\\\ &=\frac{\pi}{2\sin(p\pi/2)}\\\\ &= \frac\pi 2 \csc(p/2) \end{align}$$
As @CaptainChicky mentioned in a comment, we could have chosen to evaluate the integral of interest using a semi-circular contour. Proceeding, note that with the branch cut chosen as before, we have
$$\int_{-\infty}^\infty \frac{x^{p-1}}{1+x^2}\,dx =(1+e^{i(p-1)\pi})\int_0^\infty \frac{x^{p-1}}{1+x^2}\,dx \tag1$$
Now let $C_R$ be the closed contour in the complex plane comrised of $(i)$ the real-line segment $[-R,R]$ and $(ii)$ the semi-circle $|z|=R$, $0\le \arg(z)\le \pi$. Then, we have for $R>1$
$$\begin{align} \oint_{C_R}\frac{z^{p-1}}{1+z^2}\,dz&=\int_{-R}^R \frac{x^{p-1}}{1+x^2}\,dx +\int_\pi^0 \frac{(Re^{i\phi})^{p-1}}{1+(Re^{i\phi})^2}\,iRe^{i\phi}\,d\phi\\\\ &=2\pi i \text{Res}\left(\frac{z^{p-1}}{1+z^2}\,dz,z=i\right)\\\\ &= \pi e^{i(p-1)\pi/2 }\tag2 \end{align}$$
Letting $R\to\infty$ and using $(1)$ and $(2)$ yields
$$\int_0^\infty \frac{x^{p-1}}{1+x^2}\,dx=\pi \frac{e^{i(p-1)\pi/2 }}{1+e^{i(p-1)\pi}}=\frac\pi2\csc(p\pi/2)$$
as expected!