zoukankan      html  css  js  c++  java
  • Get请求-Test版

    package com.fanqi.test;
    
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    
    public class TestGet {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            HttpResponse hs = null;
            String url = "http://gc.ditu.aliyun.com/geocoding?a=%E8%8B%8F%E5%B7%9E%E5%B8%82";
            HttpGet hg = new HttpGet(url);
            HttpClient hc = new DefaultHttpClient();
            try {
                hs = hc.execute(hg);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            HttpEntity he = hs.getEntity();
            try {
                InputStream in = he.getContent();            
                DataInputStream d = new DataInputStream(in);
                String str = d.readLine();
                String str1 = str.substring(1, str.length()-1);
                String[] s = str1.split(",");
                for(int i=0;i<s.length;i++){
                    String t = s[i];
                    String[] tt = t.split(":");
                    if(tt.length==2){
                        String key = tt[0].replace(""", "");
                        String value = tt[1].replace(""", "");
                        System.out.println(key + ":" + value);
                    }else{
                        String key = tt[0].replace(""", "");
                        System.out.println(key + ":" + "null");
                    }
                }
                
            } catch (IllegalStateException | IOException e) {
                e.printStackTrace();
            }
        }
    
    }
  • 相关阅读:
    基于python+django+mysql的接口测试平台
    firefox没有装在C盘,webdriver启动firefox时报错
    Python知识点面试题
    Python面试题整理
    Python程序猿面试杂谈
    Python面试-websocket及web框架
    Python面试-DB相关
    Python面试简介及并行并发
    flink-demo2
    flink-table demo
  • 原文地址:https://www.cnblogs.com/fqfanqi/p/6183300.html
Copyright © 2011-2022 走看看