The hosts' greater experience eventually told in the second period, however, once Mo Eisa tapped in from close range to give them the lead just shy of the hour mark.
As the visitors pressed forwards for an equaliser, Peterborough began to pick West Ham off and eventually scored twice more through Serhat Tasdemir and Eisa again to seal progression into the third round.
One big positive for the Academy of Football on Tuesday evening was the return to action of forward Nathan Holland after a nine-month spell out with injury.
Halajko told whufc.com: “It's been nine months since Nathan Holland played his last game of football, so it's been a long, hard road to recovery for him.
“Fair play to him for working so hard on his rehabilitation to get himself back to playing, because I know it's been tough.
“It was great to have him back on the pitch and he deserves it. Nine months without playing is a long time – it's great to have him back out there."