It is a standard fact that if $X$ is a path-connected CW-complex, then: $$[X,K(G,n)] = H^n(X;G)$$ where:
- $G$ is an abelian group;
- $n>1$ is an integer;
- $K(G,n)$ is the Eilenberg-Maclane space;
- $[X,K(G,n)]$ is the set of homotopy classes of maps $X \to K(G,n)$;
- $H^n(X;G)$ is the $n$th singular cohomology of $X$ with coefficients in $G$.
For example, when $X = S^k$, LHS becomes $[S^k,K(G,n)] = \pi_k(K(G,n)) = \begin{cases} G & k=n \\ 1 & k \ne n \end{cases}$, and RHS becomes $H^n(S^k;G) = \begin{cases} G & k=0,n \\ 0 & k \ne 0,n \end{cases}$, (and obviously $0=1$).
Is there a counter-example when $X$ is not a CW-complex? So, is there a path-connected topological space $X$, abelian group $G$, and integer $n>1$, with $[X,K(G,n)] \ne H^n(X;G)$?