Foster struck the post from the spot late in the first half as coach Hugo Broos rested several of his regulars in a final match before they head to their base camp in Pachuca, Mexico.
South Africa dominated possession against a team ranked 71 places below them, but created very little against the visitors, who barely managed to get out of their own half.
The next assignment for the side is a friendly against Jamaica on June 5.
South Africa take on co-hosts Mexico in the World Cup opener in Mexico City on June 11, before a clash with the Czech Republic in Atlanta on June 18 and a final Group A fixture against South Korea six days later in Monterrey.

Rested regulars
Broos mostly rested the Mamelodi Sundowns players who lifted the CAF Champions League last Sunday, except for Themba Zwane, who started as captain of the side.
Olwethu Makhanya was handed a debut in the heart of defence, while Kamogelo Sebelebele started on the right wing in his eighth cap, remarkably the first he has played outside of Bloemfontein.
Ime Okon started in central defence alongside Makhanya and Ricardo Goss was in goal.
Penalty miss
Zwane missed an excellent early chance after good work on the right by Sebelebele when he failed to connect with a low cross into the six-yard box. Tshepang Moremi took the wrong option when he tried to score from a tight angle rather than cross for Lyle Foster.
South Africa won a penalty on 43 minutes when Sebelebele latched onto an excellent ball from Foster. He went down in the box, though the touch from Nicaragua's Justing Cano was minimal and it looked as though the winger made the most of it, making it a fortunate award from Lesotho referee Lebalang Mokete.
But Foster struck the post and wasted the opportunity. Perhaps it was justice as the first half finished 0-0.

Changes at the break
Broos made a host of changes at the break, with Sipho Chaine, Relebohile Mofokeng, Thapelo Maseko, Oswin Appollis and Iqraam Rayners all introduced, and there was an uptick in energy and quality.
Bradley Cross was handed a debut on 67 minutes as Broos made further changes in a desperate search for a goal that looked as though it would never come, with Nicaragua sitting deep in a low block and simply defending for their lives.
Different ball game
This is a totally different type of game to the ones Bafana Bafana will face at the World Cup. Here they dominated possession against a team that never even tried to get out of their own half but could not find a goal.
At the World Cup they will more likely be the team on the back foot and in defensive mode, looking to hit their opponents on the break.
That they created very little is certainly a concern, and the narrative of where the goals will come from at the World Cup was given further fuel by this performance.

Broos' reaction
“I think we can be happy with the performance today. The difficulty was that we came up against a very negative opponent. Nicaragua spent almost the entire 90 minutes defending, kicking the ball forward and trying to slow the game down whenever possible. That made it very difficult for us.
“We missed the penalty and, if we score that goal, I think the game changes completely because they would have been forced to come out and try something. But they never really tried to attack today, they only defended,” he said.
“I am sure the World Cup will be different. I don't think we will face opponents who play in that way. Even the constant stoppages and players going down would not happen in the same way because of the rules that are now in place.
“I don't really know what Nicaragua wanted to achieve from this game, but for us it was very difficult to find spaces against a team that defended so deep. We also needed a little bit of luck. We created some chances and could have scored, but overall I am satisfied because I know how difficult this type of game was for us today.”
