I got failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in php

My guess would be

$link = file_get_contents("http://www.abcdef.com/wl/api/allresults?state=".urlencode($location->state)."&page=".urlencode($page));

You might not need the second one if your $page parameter is URL-safe.