0

小さなテキストがポジティブ、ネガティブ、ニュートラルのいずれであるかを見つけるために、Sentiment-140が提供するパブリックAPIを使用しています。単純なHTTP-JSONサービスは正常に使用できますが、CURLで失敗します。これが私のコードです:

public static void makeCURL(String jsonData) throws MalformedURLException, ProtocolException, IOException {
    byte[] queryData = jsonData.getBytes("UTF-8");

    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.1.1", 8080));
    HttpURLConnection con = (HttpURLConnection) new URL("http://www.sentiment140.com/api/bulkClassifyJson").openConnection(proxy);
    con.setRequestMethod("POST");
    con.setDoOutput(true);

    OutputStream os = con.getOutputStream();
    InputStream instr = con.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(instr));

    os.write(queryData);
    os.close();
    String lin;
    while((lin = br.readLine())!=null){
        System.out.println("[Debug]"+lin); // I expect some response here But it's not showing anything            
    }
}

私は何が間違っているのですか?

4

1 に答える 1

0

接続の入力ストリームを取得する前に、すべてのリクエスト データを送信する必要があります。

byte[] queryData = jsonData.getBytes("UTF-8");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.1.1", 8080));
HttpURLConnection con = (HttpURLConnection) new URL("http://www.sentiment140.com/api/bulkClassifyJson").openConnection(proxy);
con.setRequestMethod("POST");
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.write(queryData);
os.close();

InputStream instr = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(instr));
String lin;
while((lin = br.readLine())!=null){
    System.out.println("[Debug]"+lin);
}
于 2013-04-04T07:23:50.423 に答える