从servlet发送post请求

时间:2012-07-20 10:19:01

标签: java apache-commons-httpclient accesscontrolexception

我一直在尝试从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);

网址为“https://accounts.google.com/o/oauth2/token”,我会根据此请求发送一些参数。

然而,当我运行这个时,我得到AccessControlException

我在这里使用的HttpPost方法来自org.apache.http,即公共HttpClient API。我已经尝试了很多,但似乎没有用。

所以问题是“是否可以使用HttpClient发送跨域请求?”

0 个答案:

没有答案
相关问题