I'm testing the net class of libgdx library to get a json from the page passed to the setUrl method. This portion of code comes from a class called ApplicationScreen that implements the libgdx Screen interface. That's the code:
@Override
public void show() {
String requestContent = null;
httpRequest = new HttpRequest(Net.HttpMethods.GET);
httpRequest.setUrl("http://localhost/projects/SqlParser/index.php");
httpRequest.setHeader("Content-Type", "text/plain");
httpRequest.setContent(requestContent);
Gdx.net.sendHttpRequest(httpRequest, new HttpResponseListener() {
public void handleHttpResponse(HttpResponse httpResponse) {
final int statusCode = httpResponse.getStatus().getStatusCode();
System.out.println("HTTP Request status: " + statusCode);
System.out.println("Content:");
System.out.println(httpResponse.getResultAsString());
}
public void failed(Throwable t) {
System.out.println("HTTP request failed!");
}
});
}
When I run the desktop version I get this message on the Console window "HTTP Request Status: 200", followed by the content of the http request, so the code does what I expect it should do. When I run instead the html version I get this message on the Console "HTTP Request status: 0". Any suggestion?
I solved the problem using an unsecured version of Google Chrome, launching the browser with these options: --allow-file-access-from-files --disable-web-security