Integration by substitution fail for $\int \frac{1}{(1+\sin x)}\, \mathrm dx$. We tried to do an integral with the universal trigonometric substitution $$\int \frac{1}{(1+\sin x)}\, \mathrm dx$$
Meaning, we substituted: $ t = \tan \frac{x}{2}  \Rightarrow$ 
$$\int \frac{1}{(1+\sin x)}\, \mathrm dx = \int \frac{\frac{2}{1+t^2}}{1+\frac{2t}{1+t^2}}\, \mathrm dt = \int \frac{2}{(1+t)^2}\, \mathrm dt = \frac{-2}{1+t} = \frac{-2}{1+\tan \frac{x}{2}} + C$$
But the answer is:
$$ \tan x - \frac{1}{\cos x} + C $$
What did we do wrong?

Another answer is 
$$
\int\frac{1}{1+\sin x} dx=-\frac{\cos x}{1+\sin x}+c
$$
To show this we write
$$
\tan x-\sec x=\frac{\sin x-1}{\cos x}=
\frac{(\sin x-1)\cos x}{\cos^2 x}=
\frac{(\sin x-1)\cos x}{1-\sin^2 x}=
\frac{(\sin x-1)\cos x}{(1-\sin x)(1+\sin x)}=
-\frac{\cos x}{1+\sin x}+c
$$
