我一直在尝试从 servlet 发送 POST 请求,我编写的代码是这样的:
HttpPost post = new HttpPost(url.build());
post.setEntity(new UrlEncodedFormEntity(nameValue));
post.setHeader("content-type", "application/json");
HttpClient client = new DefaultHttpClient();
HttpResponse res = client.execute(post);
URL 是“https://accounts.google.com/o/oauth2/token”,我在这个请求中发送了一些参数。
但是,当我运行它时,我得到AccessControlException
.
我这里使用的HttpPost
方法来自org.apache.http
即commons HttpClient API。我已经尝试了很多,但它似乎不起作用。
所以问题是“是否可以使用 HttpClient 发送跨域请求?”