why $\int \frac{1}{1+\sin(x)+\cos(x)}dx = \ln\left | \tan(\frac{x}{2})+1 \right |+const.$? This is how I solve $$\int \frac{1}{1+\sin(x)+\cos(x)}dx$$, but I got the wrong answer, and the correct answer is $$\ln\left | \tan(\frac{x}{2})+1 \right |+\text{const}.$$
How to solve this？

 A: When you substitute $\frac{du}{dx}$ in for $\sec^2\frac{x}{2}$, you forgot about the $\frac{1}{2}$. You needed to sub in $2\frac{du}{dx}$.
A: The two answers are "the same" since $\log(2\tan(x/2)+2)=\log 2+\log(\tan(x/2)+1$. The rest is taken care of by the arbitrary constant of integration.
Remark: There are slightly easier ways to handle this integral. Using the double-angle formulas for sine and cosine, we find that we want to integrate
$$\frac{1}{2}\cdot \frac{1}{\sin(x/2)\cos(x/2)+\cos^2(x/2)}.$$
Divide top and bottom by $\cos^2(x/2)$. We find that we want to integrate
$$\frac{1}{2}\cdot\frac{\sec^2(x/2)}{1+\tan(x/2)}.$$
Now make the substitution $u=1+\tan(x/2)$. 
A: \begin{align}
\sin x &= \frac{2\tan(x/2)}{1 + \tan(x/2)} \\
\cos x &= \frac{1-\tan^2x}{1+ \tan^2x} \\
1+\sin x+\cos x &= \frac{2 + 2\tan(x/2)}{1+\tan(x/2)} \\
I &= \int\frac{dx}{1+\sin x+\cos x} \\
&= \int\frac{\sec(x/2)}{2+\tan(x/2)} dx
\end{align}
Let $z=\tan(x/2)$, then $dz=\frac12\sec(x/2)dx$ and
\begin{align}
I &= \int \frac22 \frac{dz}{1+z} \\
&= \log|z+1| +c \\
&= \log(\tan(x/2)+1) + c
\end{align}
