HttpURLConnection returns error 503 when accessing through a proxy server

I am working on creating a video sitemap for a site that hosts videos on the Brightcove video area. To get all the video information from the site, Brightcove offers to read the answer from his URL of the following form

http://api.brightcove.com/services/library?token="+accountToken+"&page_size=1&command=find_all_videos&output=JSON&get_item_count=true

url output is in JSON where accountTokenis just an account id.

When I hit the above Token URL in the browser, it gives me the correct answer.

I wrote below a fragment of a program for reading from this URL

URL jsonURL = new URL("http://api.brightcove.com/services/library?token="+accountToken+"&page_size=1&command=find_all_videos&output=JSON&get_item_count=true");
        HttpURLConnection connection = (HttpURLConnection) jsonURL.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(connection.getInputStream()));
        String lineRead = "";
        while (reader.ready()) {
            lineRead = lineRead + reader.readLine();
        }

As my browser uses a proxy server, I added the code below to enable proxy settings

        System.setProperty("http.proxyHost", "my.proxyurl.com");
        System.setProperty("http.proxyPort", "80");

Without using the proxy server settings, it returns java.net.ConnectException: Connection refused: connectand with the proxy server it gives mejava.io.IOException: Server returned HTTP response code: 503

, : 503 (Service Unavailable)? .

1: . , , "Request Timed out". , HTTP. .

+5
2

, , , 503(Service Unavailable). ( ), . :

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", "port));
conn = new URL(jsonURL).openConnection(proxy);

- SOCKS, Proxy Proxy.Type.SOCKS.

+3

Jamas minor code correction

String host="myproxy.com";
int port=8080;
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
0
source

All Articles