TITLE: How to evaluate this integral $\int_{-\infty}^{+\infty}\frac{x^2e^x}{(1+e^x)^2}dx$?
QUESTION [10 upvotes]: I need to evaluate $$\int_{-\infty}^{+\infty}\frac{x^2e^x}{(1+e^x)^2}dx$$
I think the answer is $\frac{\pi^2}{3}$, but I'm not able to calculate it.

REPLY [6 votes]: Slightly more generally, consider 
$$J(P,R) = \oint_\Gamma \frac{P(z)\; e^z\; dz}{(1+e^z)^2}$$
where $P$ is a polynomial and $\Gamma$ is the positively oriented rectangular contour from $-R$ to $R$ to $R+2\pi i$ to $-R+2\pi i$.  Then $J(P,R) = 2 \pi i \text{Res}(P(z)\; e^z/(1+e^z)^2,z=\pi i) = - 2 \pi i P'(\pi i)$. 
On the other hand, it is easy to see that the contributions to the integral from the vertical sections go to $0$ as $R \to \infty$, and
$$ \lim_{R \to \infty} J(P,R) = \int_{-\infty}^\infty \frac{(P(x) - P(x+2\pi i)) e^x}{(1+e^x)^2}\ dx$$
Now $P(x) - P(x + 2 \pi i) = x^2$ for $P(z) = -\dfrac{\pi i}{3} x + \dfrac{1}{2} x^2 + \dfrac{i}{6 \pi} x^3$,  which makes $- 2 \pi i P'(\pi i) = \dfrac{\pi^2}{3}$.