I was playing around with the function $\dfrac{1}{1+x^2}$, and knowing that the integral over $(0,\infty)$ was $\dfrac{\pi}{2}$, I was hoping to see if there was some neat pattern to determining the value of the following generalized form: $$I=\int_0^\infty \frac{dx}{1+x^n}$$ for natural $n\ge2$. I ran some computations in Mathematica and got a consistent result of $\dfrac{\pi}{n}\csc\left(\dfrac{\pi}{n}\right)$, which also happens to be equivalent to $\dfrac{1}{n}\Gamma\left(\dfrac{1}{n}\right)\Gamma\left(1-\dfrac{1}{n}\right)=\mathrm{B}\left(\dfrac{1}{n},1-\dfrac{1}{n}\right)$.
Is there some neat trick I can use to get this result? I've considered integrating along a contour, but I'm somewhat rusty with complex methods. Also, the result was posted previously here.
I tried something like this instead: $$\frac{1}{1+x^n}=\begin{cases}\displaystyle \sum_{k=0}^\infty(-1)^kx^{nk}&\text{for }|x|<1\\\\ \displaystyle\sum_{k=0}^\infty (-1)^k x^{-n(k+1)}&\text{for }|x|>1\end{cases}$$ then integrating along the respective intervals $(0,1)$ and $(1,\infty)$.
Here's my attempt: $$\begin{align*}I &=\left\{\int_0^1+\int_1^\infty\right\}\frac{dx}{1+x^n}\\\\ &=\sum_{k=0}^\infty \left\{\int_0^1 (-1)^kx^{nk}\,dx+\int_1^\infty (-1)^kx^{-n(k+1)}\,dx\right\}\\\\ &=\sum_{k=0}^\infty \left\{(-1)^k\left[\frac{x^{nk+1}}{nk+1}\right]_{0}^{1}+(-1)^k\left[\frac{x^{-n(k+1)+1}}{-n(k+1)+1}\right]_1^\infty\right\}\\\\ &=\sum_{k=0}^\infty \left\{\frac{(-1)^k}{nk+1}-\frac{(-1)^{k}}{1-n(k+1)}\right\}\\\\ &=\left(1-\frac{1}{1-n}\right)+\left(-\frac{1}{n+1}+\frac{1}{1-2n}\right)\\ &\quad\quad+\left(\frac{1}{2n+1}-\frac{1}{1-3n}\right)+\left(-\frac{1}{3n+1}+\frac{1}{1-4n}\right)+\cdots\\\\ &=1-\frac{2}{1-n^2}+\frac{2}{1-4n^2}-\frac{2}{1-9n^2}+\cdots\\\\ &=\sum_{k=0}^\infty \frac{(-2)^k}{1-(kn)^2}\end{align*}$$ However, this series diverges by the ratio test, so I'm not sure if I made a mistake in my calculation or used some flawed reasoning.