How to integrate $1/(\sin x + a\sec x)^2$? How to integrate $1/(\sin x + a\sec x)^2$?
I tried by squaring the contents and trying to make use of some identities, but it became very messy and difficult to solve.
 A: $\displaystyle I(a) = \int \dfrac{\mathrm{d}x}{(\sin x + a\sec x)^2}$
Multiplying the numerator and denominator by $\cos^2x,$ 
$\displaystyle I(a) = \int \dfrac{\cos^2x\,\mathrm{d}x}{(\sin x\cos x + a)^2}$
$\displaystyle I(a) = \int \dfrac{\cos^2x\,\mathrm{d}x}{\sin^2x\cos^2x + 2a\sin x\cos x + a^2}$
$\displaystyle I(a)= \int \dfrac{\cos^2x\,\mathrm{d}x}{a^2 + a\sin 2x + \frac{\sin^22x}{4}}$
$\displaystyle I(a)= \int \dfrac{4\cos^2x\,\mathrm{d}x}{(4a^2 + 4a\sin2x + \sin^22x)} = 2\int\dfrac{(1+\cos 2x)\,\mathrm{d}x}{(2a + \sin2x)^2}$
$\displaystyle I(a) = 2\underbrace{\int\dfrac{\mathrm{d}x}{(2a + \sin2x)^2}}_{I_1} + 2\underbrace{\int\dfrac{\cos 2x\,\mathrm{d}x}{(2a + \sin2x)^2}}_{I_2}$
Evaluating $I_2$ should be easy, we let $(2a + \sin 2x) = t \implies 2\cos 2x\,\mathrm{d}x = \mathrm{d}t$
$\displaystyle I_2 = \dfrac{1}{2}\int \dfrac{\mathrm{d}t}{t^2} = -\dfrac{1}{2}\cdot\dfrac{1}{(2a + \sin 2x)} + C$
Solving $I_1$ is a bit challenging,
Assume $Z = \dfrac{\cos2x}{2a + \sin 2x}$
$\dfrac{dZ}{dx} = \dfrac{(2a + \sin2x)(-2\sin2x) - \cos 2x(2\cos2x)}{(2a + \sin 2x)^2}$
$\implies \dfrac{dZ}{dx} = \dfrac{-4a\sin 2x -2}{(2a + \sin 2x)^2}$
$\implies \dfrac{dZ}{dx} = \dfrac{-4a(\sin 2x + 2a) - 2 + 8a^2}{(2a + \sin 2x)^2}$
$\implies \dfrac{dZ}{dx} = -\dfrac{4a}{(2a + \sin 2x)} + \dfrac{(8a^2 - 2)}{(2a + \sin 2x)^2}$
Now integrate both sides w.r.t $x,$
$\displaystyle Z = -4a\int\dfrac{\mathrm{d}x}{(2a + \sin2x)} + (8a^2 - 2)I_1$
$\displaystyle\implies (8a^2 - 2)I_1 = Z + 4a\int\dfrac{\sec^2x\mathrm{d}x}{2a + 2\tan x + 2a \tan^2x}$
Substitute $\tan x = p,$
$\displaystyle (8a^2 - 2)I_1 = Z + \dfrac{4a}{2a}\int\dfrac{dp}{p^2 + \frac{p}{a} + 1} = Z + 2\int\dfrac{dp}{\left(p + \frac{1}{2a}\right)^2 + \left(1 - \frac{1}{4a^2}\right)}$
$\implies (8a^2 - 2)I_1 = Z + \dfrac{4a}{\sqrt{4a^2 - 1}}\tan^{-1}\left(\dfrac{2ap + 1}{\sqrt{4a^2 - 1}}\right)$
$\implies (8a^2 - 2)I_1 = \dfrac{\cos 2x}{2a + \sin 2x} + \dfrac{4a}{\sqrt{4a^2 - 1}}\tan^{-1}\left(\dfrac{2ap + 1}{\sqrt{4a^2 - 1}}\right)$
$\implies I_1 = \dfrac{1}{(8a^2 - 2)}\cdot\dfrac{\cos 2x}{2a + \sin 2x} + \dfrac{2a}{(4a^2 - 1)^{3/2}}\tan^{-1}\left(\dfrac{2ap + 1}{\sqrt{4a^2 - 1}}\right)$
Hence we finally obtain $I$ as,
$\boxed{I(a) = \dfrac{1}{(4a^2 - 1)}\dfrac{\cos 2x}{(2a + \sin 2x)} + \dfrac{4a}{(4a^2 - 1)^{3/2}}\tan^{-1}\left(\dfrac{2a\tan x + 1}{\sqrt{4a^2 - 1}}\right) - \dfrac{1}{2a + \sin 2x} + C}$
A: lab bhattacharjee's hint  make things rather simple.
Let $$\tan(x) =y \implies x=\tan ^{-1}(y)\implies dx=\frac{dy}{1+y^2}$$ After simplifications, this leads to
$$\int\dfrac{dx}{(\sin x+a\sec x)^2}=\int\frac{dy}{\left(a y^2+y+a\right)^2}$$ Let $r$ and $s$ be the roots of the quadratic $ay^2+y+a=0$. This makes
$$\frac{1}{\left(a y^2+y+a\right)^2}=\frac 1{a^2(y-r)^2(y-s)^2}$$ Now, partial fraction decomposition
$$\frac 1{(y-r)^2(y-s)^2}=\frac{2}{(r-s)^3 (y-s)}+\frac{1}{(r-s)^2 (y-s)^2}-\frac{2}{(r-s)^3
   (y-r)}+\frac{1}{(r-s)^2 (y-r)^2}$$ which seems to be easily workable.
