我需要一点帮助,我是在 java 中创建休息方法的新手,但我找到了它并创建了一个休息方法。我有一个包含不同方法的类。这是我的课
@Path("/WebServices ")
public class WebServices {
@POST
@Path("/SourceCreateService")
@Consumes("multipart/related")
@Produces("text/plain")
public String sourceCreateService(@QueryParam("sourceTiltle") String sourceTiltle, @QueryParam("xml") String xml) {
return "name";
}
}
And now i have to access this method in another class,I can use this code to access this method in this class,
try{
URL url = new URL("http://localhost:8080/web/WebServices/SourceCreateService?sourceTiltle=sdds&xml="XML");
URLConnection conn = url.openConnection();
conn.setDoOutput(true); // Triggers POST.
// conn.setDoInput(true);
conn.setRequestProperty("Accept-Charset", charset);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
BufferedWriter out =
new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
out.write("username=name\r\n");
out.flush();
out.close();
BufferedReader in =
new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
}catch(IOException e){
system.out.println(""+e);
}
when i call this method i got this error,
java.io.IOException: Server returned HTTP response code: 505 for URL:
I put debugpoint in web service method also,but it not come to that method,it directly throws exception here,so my question is that my webservice methog is right and kindly tell me what is the wrong in my code and my URL
web.xml中是否有任何配置