My question comes from the fact that $\langle K(G,n),K(H,n)\rangle = \text{Hom}(G,H)$. The only proof of this fact that I know uses $\langle X,K(H,n)\rangle = H^n(X,H)$.
However, this way of reasoning cannot be extended to obtain the following generalization of the previous fact about Eilenberg-Maclane spaces. If $X$ is $(n-1)$-connected CW-complex and $Y$ is path-connected CW-complex with $\pi_i(Y)=0$ for all $i>n$, then $\langle X,Y\rangle$ is in bijection with $\text{Hom}(\pi_n(X),\pi_n(Y))$. What is a good strategy for attacking this problem?