2016-09-11 7 views
1

チャレンジブラケットを試して取得するリクエストを送信すると、実際のブラケットの代わりにrobots.txtファイルが取得されます。同じURLをコピーしてブラウザに貼り付けると、目的のJSON括弧が得られます。私は何が間違っているのだろうと思っていたし、次のJavaメソッドがmetaname = robotsテキストファイルの代わりに実際にブラケットを返すようにする方法を考えました。例えばHTTP Challongeにリクエストを返すrobots.txtを返します

public String httpGett(String url,String userAgent) throws Exception{ 
    String USER_AGENT = userAgent; 
    URL obj = new URL(url); 
    HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 

    con.setRequestMethod("GET"); 

    con.setRequestProperty("User-Agent", USER_AGENT); 

    int responseCode = con.getResponseCode(); 
    System.out.println("\nSending 'GET' request to URL : " + url); 
    System.out.println("Response Code : " + responseCode); 

    BufferedReader in = new BufferedReader(
      new InputStreamReader(con.getInputStream())); 
    String inputLine; 
    StringBuffer response = new StringBuffer(); 

    while ((inputLine = in.readLine()) != null) { 
     response.append(inputLine); 
    } 
    in.close(); 

    //System.out.println(response.toString()); 
    return(response.toString()); 
} 

、私が送信されたURLは

https://challonge.com/api/tournaments/example.json?include_matches=1&include_participants=1&api_key=[MY APIキー]

だったと私は、私はなるだろう、私のブラウザにURLを入力した場合: http://pastebin.com/4W4kmdJV

そして、私ならば私のJavaメソッドを使用して取得するリクエストを送信します。 http://pastebin.com/ifYSSzu3

Javaメソッドから正しいブラケット情報を取得するにはどうすればよいですか?

答えて

関連する問題