posts - 431,  comments - 344,  trackbacks - 0

          兩天前寫了個通過上海中科院有機化學研究所網站的翻譯功能來翻譯化合物名稱的Python代碼,今天看到了HttpClient也比較好用,所以就寫了個,代碼如下:

            HttpClient httpclient = new DefaultHttpClient();
            HttpPost method = new HttpPost("http://202.127.145.134/scdb/translate/translate.asp");
            
            List <NameValuePair> nvps = new ArrayList <NameValuePair>();
            nvps.add(new BasicNameValuePair("eng2chi", "BISPYROQUINE"));    //參數
                  
            try {
             method.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));   //設置參數給Post
             HttpResponse response = httpclient.execute(method);
             HttpEntity entity = response.getEntity();
             BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "gb2312"));
             
             String line = null;
             while ((line = reader.readLine()) != null) {
              System.out.println(line);
             }
             if (entity != null) {
              entity.consumeContent();
             }

            } catch (ClientProtocolException e) {
             e.printStackTrace();
            } catch (UnsupportedEncodingException e1) {
             e1.printStackTrace();
            } catch (IOException e) {
             e.printStackTrace();
            }

          posted on 2009-07-30 16:48 周銳 閱讀(1674) 評論(0)  編輯  收藏 所屬分類: ApacheJava
          主站蜘蛛池模板: 甘肃省| 固始县| 台前县| 类乌齐县| 永吉县| 政和县| 庐江县| 双城市| 宝清县| 星座| 武城县| 涞水县| 介休市| 岳西县| 德阳市| 垫江县| 灵川县| 增城市| 三穗县| 泾阳县| 永德县| 和静县| 威宁| 盐池县| 尼勒克县| 岫岩| 娱乐| 泸水县| 沙洋县| 阜平县| 比如县| 汝阳县| 贵德县| 醴陵市| 青海省| 武强县| 汤阴县| 南木林县| 新沂市| 中方县| 海丰县|