0

私はモーニングスターのプレミアム アカウントを持っており、プレミアム コンテンツ エリアからいくつかの csv ファイルをダウンロードしようとしました。何らかの理由で、それらのプレミアム コンテンツを取得できません。たとえば、プレミアム アカウントでは 10 年間の財務諸表データを取得できますが、Apache httpcomponents-client のサンプル認証 Java コードはすべて試しました。それらはすべて、認証を必要としないコンテンツのみを取得できます。モーニングターが使用している認証プロトコルを確認し、正常に認証するにはどうすればよいですか? clientAuthentication.java、clientKerberosAuthentication.java、clientInteractiveAuthentication.java など、org.apache.http.examples.client のサンプル コードを試しました。Chrome でモーニングスター アカウントにログインしてこの URL を貼り付けると 10 年分のデータの csv が取得できますが、java からアクセスすると 5 年分のデータしか取得できません。以下は、私が試したサンプルコードの1つです。例外やエラーは発生しませんでしたが、10 年ではなく 5 年分のデータしか得られませんでした。

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;


public class ClientAuthentication {

    public static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope("morningstar.com", 443),
                    new UsernamePasswordCredentials("xxx@gmail.com", "xxxx")); //anonymized this before posting to stackoverflow

            HttpGet httpget = new HttpGet("http://financials.morningstar.com/ajax/ReportProcess4CSV.html?t=aapl&region=usa&culture=en_US&reportType=is&period=12&dataType=A&order=asc&columnYear=10&rounding=3&view=raw&productCode=USA&r=199209&denominatorView=raw&number=3");

            System.out.println("executing request" + httpget.getRequestLine());
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            BufferedReader in;
            in = new BufferedReader(new InputStreamReader(entity.getContent()));

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
                int linenum = 0;
                while (true){
                    String line = in.readLine();
                    if (line == null) break;
                    linenum++;  
                    if (linenum>1)
                    System.out.println(line);

                }
            }
            EntityUtils.consume(entity);
        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }
}
4

0 に答える 0