Socket获取天气
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; public class TalkClient { public static void main(String[] args) { try{ //向本机的4700端口发出客户请求 Socket socket=new Socket("restapi.amap.com",80); //由Socket对象得到输出流,并构造PrintWriter对象 PrintWriter os=new PrintWriter(socket.getOutputStream()); os.println("GET https://restapi.amap.com/v3/weather/weatherInfo?city=370883&key=。。。&output=xml"); os.flush(); //由Socket对象得到输入流,并构造相应的BufferedReader对象 BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));