0

当我在 java 中调用它时:

URL url = new URL("http://www.google.com/finance/getprices?q=MSFT");
URLConnection goog = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(goog.getInputStream()));

我将此视为例外:

java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.google.com/sorry/?continue=http://www.google.com/finance/getprices%3Fq%3MSFTO%26

我的函数中没有转换 URL,因为它在调用我的 URL 时自动生成,我的原始 URL 是“continue =”之后的字符串,我怎样才能从这个 URL 中取回它?

编辑 :

因为我一次又一次地调用这个页面,它会生成这个 URL http://www.google.com/sorry/?continue=http://www.google.com/finance/getprices%3Fq%3MSFTO%26它说:

我们的系统检测到来自您的计算机网络的异常流量。此页面检查是否真的是您发送请求,而不是机器人。如果我在 continue= 之后复制粘贴 URL,它会给我页面的实际内容。

4

1 回答 1

0

503 是一个响应代码,告诉服务已关闭或不可用

维基链接

根据维基百科

503 Service Unavailable
The server is currently unavailable (because it is overloaded or down for maintenance).[2] Generally, this is a temporary state.

我已经尝试过你的代码,这很好(没有例外)

    URL url = new URL("http://www.google.com/finance/getprices?q=MSFT");
    URLConnection goog = url.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(goog.getInputStream()));
    String temp;
    while((temp = in.readLine())!= null){
        System.out.println(temp);
    }
    }catch(Exception ex){
        ex.printStackTrace();
    }

它还给我

EXCHANGE%3DNASDAQ
MARKET_OPEN_MINUTE=570
MARKET_CLOSE_MINUTE=960
INTERVAL=86400
COLUMNS=DATE,CLOSE,HIGH,LOW,OPEN,VOLUME
DATA=
TIMEZONE_OFFSET=-240
a1370289600,35.59,35.63,34.83,34.92,51256272
1,34.99,35.74,34.771,35.62,65538438
2,34.78,34.89,34.43,34.6,46032657
3,34.96,35.11,34.49,34.84,37627133
4,35.67,35.78,35.06,35.25,40762249
7,35.47,35.65,35.14,35.51,35995223
8,34.84,35.18,34.68,35.05,39350316
9,35,35.27,34.85,35.14,37373032
10,34.715,35.02,34.59,34.99,45654803
11,34.4,34.6901,34.25,34.55,53116371
14,35,35.16,34.63,34.69,49672492
15,34.98,35.17,34.895,34.97,28622929
16,34.59,35.09,34.59,34.96,30820208
17,33.49,34.33,33.37,34.26,54496758
18,33.265,33.73,33.05,33.66,85338395
21,33.715,34.2,32.57,32.94,56113708
22,33.67,34.38,33.46,34.08,44073348
23,34.35,34.48,33.8875,34.12,48667834
24,34.62,34.78,34.5,34.52,28993542
25,34.545,34.79,34.34,34.38,65548196
28,34.36,34.99,34.33,34.75,31064000

所以问题可能是您所在地区暂时不提供服务。

于 2013-07-02T07:07:15.473 回答