我正在尝试使用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();
}
}
任何帮助将不胜感激。
答案 0 :(得分:0)
response.body().string()
而非$('#start-form').on('submit',function(event){
event.preventDefault();
status();
});
function status() {
$.ajax({
url : "status_page/", // the endpoint
type : "POST", // http method
data:{' ': '',}, // data sent with the post req
headers: {Accept: "application/json"},
success : function(json) {
//on success display the rendered page,so what coding is needed here?
},
error : function(xhr,errmsg,err) {
//error handling code }
});
}
。 toString()
。System.out.println
说getMsg()
,但您的构建回复是@Produces("application/json")
。