To solve a DE with substitution, we first observe that we are given an equation with $x$ and $y$ variables, that is $x \frac{dy}{dx} + 2 y = xy^2$ then we introduce $u = x^2 y$. Here, our intention is to remove our $y$ variables and replace it with $u$ instead.

So we should proceed to find $\frac{du}{dx}$.
$\frac{du}{dx} = 2x y + x^2 \frac{dy}{dx}$
Since $x \frac{dy}{dx} + 2 y = xy^2$, we have that $\frac{dy}{dx} + 2 \frac{y}{x} = y^2$.
$\Rightarrow \frac{du}{dx} = 2x y + x^2 (y^2 - 2 \frac{y}{x})$
$\frac{du}{dx} = 2x y + x^2 y^2 - 2 x y$
$\frac{du}{dx} = x^2 y^2$
$\frac{du}{dx} = \frac{u^2}{x^2}$
$\frac{1}{u^2} \frac{du}{dx} = \frac{1}{x^2}$
$\int \frac{1}{u^2} du = \int \frac{1}{x^2} dx$
$-\frac{1}{u} = -\frac{1}{x}+c$
$-\frac{1}{x^2 y} = -\frac{1}{x}+c$
$\frac{1}{x^2 y} = \frac{1}{x}+c$
All we need to do now, is to make $y$ in terms of $x$.