简体   繁体   English

无法从邮递员读取文件

[英]unable to read the file from postman

I was trying postman with a Java clientava client. 我正在尝试使用Java clientava客户端的邮递员。 I was getting the following output 我得到以下输出

com.squareup.okhttp.internal.http.RealResponseBody@c9673cf

the original output is 原始输出是

Curl -I "http://ec2-52-34-14-38.us-west-2.compute.amazonaws.com:14000/webhdfs/v1/user/ec2-user/prediction_output/part-00000?user.name=ec2-user&op=OPEN"

1234.566788

here is my java code. 这是我的Java代码。

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import java.io.IOException;
@Path("/hello")
public class HelloWorldService {
@GET
@Produces("application/json")
public Response getMsg() throws IOException {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://ec2-52-34-14-38.us-west-2.compute.amazonaws.com:14000/webhdfs/v1/user/ec2-user/prediction_output/part-00000?user.name=ec2-user&op=OPEN")
 .build();
 com.squareup.okhttp.Response responses = null;
 responses = client.newCall(request).execute();
 System.out.println(responses);
 return Response.status(200).entity(responses.body().toString()).build();
}
} 

any help will be appreciated. 任何帮助将不胜感激。

  • Use response.body().string() not toString() . 使用response.body().string()而不是toString()
  • Use the above also in System.out.println . 也可以在System.out.println使用以上内容。
  • Your method getMsg() says @Produces("application/json") but your built response is text/plain . 您的方法getMsg()@Produces("application/json")但是您建立的响应是text/plain

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM