【发布时间】:2016-05-28 07:07:51
【问题描述】:
每当用户点击 chrome 扩展时,我想将 URL 字符串发送到 java 模块。
这是我的 JS 代码
document.addEventListener('DOMContentLoaded', function () {
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
alert(tabs[0].url)
var http = new XMLHttpRequest();
var someValue = "http://chums/chummi";
var url = "http://localhost:8080/SalesRESTservice/apicall/restcall2/";
http.open("GET", url, true);
http.setRequestHeader("Content-type", "application/json; charset=utf-8");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(someValue);
});
});
这是我的 Java
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.json.JSONException;
import org.json.JSONObject;
@Path("/restcall2")
public class restcall2 {
@Path("{f}")
@GET
@Produces("text/plain")
public Response RESTcall(@PathParam("f") String f) throws JSONException {
return Response.status(200).entity(f).build();
}
}
每当我尝试点击 URL http://localhost:8080/SalesRESTservice/apicall/restcall2/
我没有得到回应。
在我的网络选项卡中,它显示
我正在使用 Tomcat 服务器来处理请求
【问题讨论】:
-
不知道为什么会收到 405 错误代码
标签: javascript java rest