织梦CMS - 轻松建站从此开始!

沙龙国际_沙龙国际娱乐城_沙龙国际娱乐官网

当前位置: 主页 > 沙龙365 >

为什么百度apistore的天气api在Java项目中能用而在

时间:2017-07-18 03:30来源:未知 作者:admin 点击:
百度apistore的天气api String httpArg = "city=beijing";@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String httpUrl = "http://apis.baidu.com/hew

百度apistore的天气api

String httpArg = "city=beijing";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String httpUrl = "http://apis.baidu.com/heweather/weather/free";
    String httpArg = "city=beijing";
    BufferedReader reader = null;
    String result = null;
    StringBuffer sbf = new StringBuffer();
    httpUrl = httpUrl   "?"   httpArg;

    try {
        URL url = new URL(httpUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("apikey","f1375c3a44007cdc331966524783f3ab");
        connection.connect();
        InputStream is = connection.getInputStream();
        reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        String strRead = null;
        while ((strRead = reader.readLine()) != null) {
            sbf.append(strRead);
            sbf.append("\r\n");
        }
        reader.close();
        result = sbf.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }

    Log.d("tag",result "-------");
}`

就这个,在安卓中返回null。
在Java项目中返回正常

织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
推荐内容