@POST
@Path("/getphotos")
@Produces(MediaType.TEXT_HTML)
public String getPhotos() throws IOException{
BufferedReader rd = new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
return "ok";
}
上面的代码用于我的服务器。 但是在这段代码中,字符串“line”没有任何值(总是) 代码有问题吗?Jersey request.getInputStream()
客户端代码
String message = "message";
URL url = new URL(targetURL);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(urlConnection.getOutputStream());
wr.write(message);
提供强大的功能以下链接将帮助您阅读请求中的行。 [链接阅读线] [1] [1]:http://stackoverflow.com/questions/5175203/httpservlet-request-getinputstream-always-receiving-blank-line – 2013-02-22 16:19:07
它是一个坏主意,使用缓冲读者可以阅读(推测)非文字信息。什么是传入的内容类型,您是否将它作为多部分数据发送? – Perception 2013-02-22 16:25:30
传入的数据是现在的字符串,但后来它将被更改为Json也发送类型将Json – 2013-02-22 16:34:05