【问题标题】:unable to read the file from postman无法从邮递员那里读取文件
【发布时间】:2015-12-11 15:28:49
【问题描述】:

我正在尝试使用 Java clientava 客户端的 postman。我得到以下输出

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

原来的输出是

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

这是我的 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();
}
} 

我们将不胜感激。

【问题讨论】:

    标签: java spring rest postman


    【解决方案1】:
    • 使用response.body().string() 而不是toString()
    • System.out.println 中也使用上述内容。
    • 您的方法getMsg()@Produces("application/json"),但您构建的响应是text/plain

    【讨论】:

    • 我也试过这个。但它仍然只显示相同的消息。
    猜你喜欢
    • 2018-10-12
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-25
    • 2017-07-08
    相关资源
    最近更新 更多