Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我可以使用GWT HTTP请求从网站读取文本文件吗?_Java_Gwt_Httprequest - Fatal编程技术网

Java 我可以使用GWT HTTP请求从网站读取文本文件吗?

Java 我可以使用GWT HTTP请求从网站读取文本文件吗?,java,gwt,httprequest,Java,Gwt,Httprequest,我已经创建了一个,我想使用一个从另一个站点读取文本文件 我将此代码放入入口点方法onModuleLoad(): 始终执行错误块,并且响应。getStatusCode()为0response.getText()和response.getStatusText()返回空白文本。GWT HTTP请求可以用于读取文本文件,还是应该使用其他方法?您不能向不同的域发出HTTP请求,因为存在问题。您是否向其他域发出请求?@Fedy2是的,我尝试了其他站点,但得到了相同的结果。 String url = "htt

我已经创建了一个,我想使用一个从另一个站点读取文本文件

我将此代码放入入口点方法onModuleLoad():


始终执行错误块,并且
响应。getStatusCode()
为0
response.getText()
response.getStatusText()
返回空白文本。GWT HTTP请求可以用于读取文本文件,还是应该使用其他方法?

您不能向不同的域发出HTTP请求,因为存在问题。

您是否向其他域发出请求?@Fedy2是的,我尝试了其他站点,但得到了相同的结果。
String url = "http://www.textfiles.com/100/apples.txt";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);

try {
    Request myrequest = builder.sendRequest(null, new RequestCallback() {

        public void onError(Request request, Throwable exception) {
        // Couldn't connect to server (could be
        // timeout, SOP violation, etc.)
        }
        public void onResponseReceived(Request request, Response response) {
            if (200 == response.getStatusCode()) {
                Label l = new Label();
                l.setText("Response: " + response.getText());
                RootPanel.get().add(l);
            }
            else {
                // Handle the error. Can get the status
                // text from response.getStatusText()
                Label l = new Label();
                l.setText("Error. getText() = " + response.getText() 
                    + " Status text = "
                    + response.getStatusText()
                    + ". Code: "
                    + response.getStatusCode());
                RootPanel.get().add(l);
            }
        }
    });
}
catch (RequestException e) {
    // Couldn't connect to server
}