我想在java上创建RESTful web服务,我选择了并得到了下面的代码。
@Path("/message")
public class Rest_test {
@Context
@SuppressWarnings("unused")
private UriInfo context;
/**
* Default constructor.
*/
public Rest_test() {
// TODO Auto-generated constructor stub
}
/**
* Retrieves representation of an instance of Rest_test
* @return an instance of String
*/
@GET
@Produces("application/xml")
public String getXml() {
// TODO return proper representation object
return "sdfgdsd";
}
/**
* PUT method for updating or creating an instance of Rest_test
* @param content representation for the resource
* @return an HTTP response with content of the updated or created resource.
*/
@PUT
@Consumes("application/xml")
public void putXml(String content) {
}
}为了测试我的应用程序,我使用程序邮递员,并从这个广告localhost:8080/test/rest/message调用我的服务器,但我总是有相同的页面HTTP状态404 -没有找到。请帮帮我
发布于 2015-11-10 19:44:10
评论是正确的!您应该调用: localhost:8080/nameOfYourService/rest/message
我也有一个TestWebService,不能突然调用它。
我创建了一个本地客户端应用程序并使用了一个httpURLconnection:
private class yourTestApp {
....
public static void getStringOrWhatEver() {
try {
URL url = new URL("http://localhost:8080/<nameOfYourService>/rest/message");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("...and the message is: ");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
System.out.println(".... End of content\n");
conn.disconnect();
} catch (MalformedURLException ex) {
System.err.println("MalformedURLException, " + ex);
} catch (IOException ex) {
System.err.println("IOException, " + ex);
}
}
....
}在这里输入图像描述
对你来说,"ps“应该是”信息“
https://stackoverflow.com/questions/33637852
复制相似问题