java和python代码行的差异

都是调用一个HTTP接口

java的确是甄环体

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class NetClientGet {

    public static void main(String[] args) {

        try {
            URL url=new URL("http://localhost:8888/RESTEipClient/erp600/material?number=1-LB&number=1-LB1");
            HttpURLConnection conn=(HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");
            if (conn.getResponseCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
            }
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (conn.getInputStream())));
            String output;
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }
            conn.disconnect();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

PYTHON

import urllib2

url="http://localhost:8888/RESTEipClient/erp600/material?number=1-LB&number=1-LB1"
f=urllib2.urlopen(url)
print f.read()
f.close()

 

 

posted @ 2013-09-27 15:59  tree.liang  阅读(576)  评论(2编辑  收藏  举报