Two methods of finding $\int_{0}^{\frac{\pi}{2}} \frac{dx}{1+\sin x}$ Two methods of finding $$I=\int_{0}^{\pi/2} \frac{dx}{1+\sin x}$$
Method $1.$ I used substitution, $\tan \left(\frac{x}{2}\right)=t$ we get
$$I=2\int_{0}^{1}\frac{dt}{(t+1)^2}=\left. \frac{-2}{t+1}\right|_{0}^{1} =1$$
Method $2.$ we have $$I=\int_0^{\pi/2}\frac{1-\sin x}{\cos ^2 x} \,\mathrm dx = \left. \int_0^{\pi/2}\left(\sec^2 x-\sec x\tan x\right)\,\mathrm dx= \tan x-\sec x\right|_0^{\pi/2}$$
What went wrong in method $2$?
 A: You are right!
Just $\lim\limits_{x\rightarrow\frac{\pi}{2}}\frac{\sin{x}-1}{\cos x}=0$
A: Don't think that discontinuities immediately imply failure. Take the left hand limit, ie. 
$$\lim_{x \to \frac \pi 2^-} \frac{\sin x - 1}{\cos x}$$
Which is indeterminate, so apply L'Hopital's rule, 
$$\lim_{x \to \frac \pi 2^-} \frac{\sin x - 1}{\cos x} = \lim_{x \to \frac \pi 2^-} \frac{\cos x} {-\sin x} = -\frac 0 1 = 0$$
Hence the result.
A: Your second integral is improper.  You divided by $1-\sin x$ which is $0$ at $\pi/2$.  So to evaluate the integral, you have to finish by taking 
$$\lim_{x \to \pi/2} (\tan x - \sec x) = 0.$$
A: Since you have used an anti-derivative $\tan x-\sec x$ which is not defined at $x=\pi/2$ we need to utilize the following result:

Theorem: If a function $f: [a, b]\to \mathbb{R} $ is Riemann integrable on $[a, b] $ then the function $F: [a, b]\to\mathbb {R} $ defined by $$F(x) =\int_{a} ^{x} f(t) \, dt$$ is continuous on $[a, b] $ and in particular $$\lim_{x\to b^{-}} \int_{a} ^{x} f(t) \, dt=\int_{a}^{b} f(t) \, dt= \lim_{x\to a^{+}} \int_{x} ^{b} f(t) \, dt$$

Using this result we have $$\int_{0}^{\pi/2}\frac{dx}{1+\sin x} =\lim_{x\to(\pi/2)^{-}}\int_{0}^{x}\frac{dt}{1+\sin t} =\lim_{x\to(\pi/2)^{-}}(\tan x-\sec x+1)=1$$ The last limit is easily evaluated using algebra of limits. 
A: \begin{align}
\tan x - \sec x & = \frac{\sin x -1}{\cos x} = \frac{(\sin x - 1)(-\sin x -1)}{(\cos x)(-\sin x - 1)} = \frac{1-\sin^2 x}{(\cos x)(-\sin x - 1)} \\[10pt]
& = \frac{\cos^2 x}{(\cos x)(-\sin x - 1)} = \frac{-\cos x}{1+\sin x} = \frac 0 2 \text{ if } x = \frac \pi 2.
\end{align}
Or you can use the identity
$$
\tan x \pm \sec x = \tan\left( \frac \pi 4 \pm \frac x 2 \right).
$$
