Integral diverges but method works? Based on this: https://math.stackexchange.com/a/4454826/595084
I want to find the integral $$I_1=\int^{\infty}_0\frac{\sin(x)}{e^x+1}\text{ d}x$$
In the method the answer uses, it converts this integral into $$I(n)=\int^{\infty}_0\frac{\sinh(nx)}{e^x+1}\text{ d}x$$ and solves for $-iI(i)$. In other words, it converted the integral into $$I_2=\int^{\infty}_0\frac{-i\sinh(ix)}{e^x+1}\text{ d}x$$
In the process of finding $I(n)$, we perform the substitutions detailed in the aforementioned answer and arrive at two integrals, namely $$A=\int^{\infty}_0\frac{x^{-n}}{x+1}\text{ d}x$$ $$B=\int^{\infty}_1x^{-n-1}\text{ d}x$$
Solving these integrals however give us some restrictions. For instance, when we solve for $B$, the upper bound forces us to place the restriction that $\Re(n)>0$ due to the fact that $\frac{1}{\infty^{bi}}$ is undefined for any constant $b$ for $b\in\mathbb{R}$.
Not only that, to solve for $A$, I set up a branch cut (since $n$ is not an integer, it can be classified as a root, and thus through testing $0$ is a branch point. We can set up starting from there in any direction) along the positive real axis and used a keyhole contour (I think I could have used a rectangular contour, but that requires 5 integrals while the keyhole has 4, so I picked the latter).
In the process of solving the integral for the outer part of the keyhole contour, I was forced to place the restriction that $0<\Re(n)<1$ to have it vanish.
In the end, the result for $I(n)$ was $$\frac{\pi}{2}\csc(\pi n)−\frac{1}{2n}$$
Plugging in $n=i$ and multiplying by $-i$ does indeed give us the correct answer. However, this is not supposed to happen.
Clearly, $\Re(i)=0$, which violates the fact that $\Re(n)>0$. As a matter of fact, if we place the substitution $n=i$ in prematurely, say into $B$, the integral even fails to converge! The upper bound basically means that we rotate around the origin an infinite amount of times. I don't even think the integral converges in a Lebesgue sense, much less Riemann.
So why is it that despite clearly violating the restrictions that exist, plugging in $n=i$ for $I(n)$ works for calculating $I_1$?
 A: As I stated in the comments, if you know that $$\int_{0}^{\infty} \frac{\sinh\left((a+ib)x \right)}{e^{x}+1} \, \mathrm dx = \frac{\pi}{2} \csc \left(\pi(a+ib) \right) - \frac{1}{2(a+ib)}$$ for $0 < a< 1$ and $b \in \mathbb{R}$, then what you need to show is that $$\lim_{a \to 0^{+}}  \int_{0}^{\infty} \frac{\sinh\left((a+ib)x \right)}{e^{x}+1} \, \mathrm dx = \int_{0}^{\infty} \frac{\sinh\left(ibx \right)}{e^{x}+1} \, \mathrm dx.$$
To show this, you can modify the argument here.
Let $(a_{n})$ be a nonnegative sequence that converges to $0$, and assume that $  a_{n} <\delta <1$.
Since the magnitude of $\sinh(z)$ increases as $\Re(z)$ increases, $$f_{n}(x) = \left|\frac{\sinh\left((a_{n}+ib)x \right)}{e^{x}+1}  \right| $$ is dominated by $$g(x) = \frac{\left|\sinh\left((\delta+ib)x \right)\right|}{e^{x}+1},  $$ which is integrable on $(0, \infty)$ since $\delta <1$.
We can therefore use the dominated convergence theorem to conclude that $$\begin{align} \lim_{n \to \infty} \int_{0}^{\infty}   \frac{\sinh\left((a_{n}+ib)x \right)}{e^{x}+1} \, \mathrm dx  &=  \int_{0}^{\infty}  \lim_{n \to \infty} \frac{\sinh\left((a_{n}+ib)x \right)}{e^{x}+1} \, \mathrm dx \\ &= \int_{0}^{\infty}  \frac{\sinh\left(ibx \right)}{e^{x}+1} \, \mathrm dx . \end{align}$$
Since this is true for all sequences $(a_{n})$ described above, the function $$F(a) = \int_{0}^{\infty} \frac{\sinh\left((a+ib)x \right)}{e^{x}+1} \, \mathrm dx$$ has a right-hand limit at $a=0$, and it's equal to $$\int_{0}^{\infty}\frac{\sinh\left(ibx\right)}{e^{x}+1} \, \mathrm dx. $$
A: Manipulations with divergent integrals requires strict proof.
Let us consider alternative way.
Are known the presentations
$$\int\limits_0^\infty e^{-kx}\sin x = \dfrac1{k^2+1},\qquad(k\ge 1)\tag1$$
$$\operatorname{csch} u=\dfrac1u+2u\sum\limits_{k=1}^\infty\dfrac{(-1)^k}{k^2\pi^2+u^2}.\tag2$$
or
$$u\operatorname{csch} u-1=2u^2\sum\limits_{k=1}^\infty\dfrac{(-1)^k}{k^2\pi^2+u^2}.$$
Then
$$I=\int\limits_0^\infty \dfrac{\sin x}{e^x+1}\text dx 
= \int\limits_0^\infty\dfrac {\sin x e^{-x}}{1+e^{-x}}\text dx
= \int\limits_0^\infty\sin x e^{-x}\sum_{k=0}^\infty (-1)^{k}e^{-kx}\text dx
=\sum\limits_{k=1}^\infty\dfrac{(-1)^{k+1}}{k^2+1},$$
$$I=\dfrac12(1-\pi\operatorname{csch} \pi).$$
