我试图使用套接字向couchdb发出POST请求,但它没有工作,我没有得到任何响应,程序也没有结束。怎么了?
Socket socket = new Socket("127.0.0.1",5984);
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
wr.write("POST /meteo/ HTTP/1.0\r\n");
wr.write("Content-Length: 245\r\n");
wr.write("Content-Type: application/json\r\n");
wr.write("\r\n");
wr.write(json.toString());//json is a JsonObject
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
wr.close();
rd.close();
}