我正在尝试在GAE云中托管的GAE应用程序中调用Google服务:
private String doPost(String URL) throws ClientProtocolException, IOException {
// Params:
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));
params.add(new BasicNameValuePair("Email", _DEFAULT_USER));
params.add(new BasicNameValuePair("Passwd", _DEFAULT_PASS));
params.add(new BasicNameValuePair("service", "ah"));
// Call
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(URL); // URL:
// https://www.google.com/accounts/ClientLogin
post.setEntity(new UrlEncodedFormEntity(p_params, HTTP.UTF_8));
post.getParams().setBooleanParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
HttpResponse response = httpClient.execute(post);
return _ProcessResponse(response); // Process...
}
执行抛出: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'remote_socket' or call 'Resolve()' was not found
。
有什么想法吗?我完全迷失了......
答案 0 :(得分:1)
您可以使用其他http客户端吗?比如推荐的here:
client = new HttpClient(new SimpleHttpConnectionManager());
或者使用URLFetchService怎么样?
根据this blog post,您需要:
&#34;自定义连接管理器,用于转换最终请求和Feed 将它们放入URL Fetch服务中,然后将响应反馈回来 进入HttpClient。&#34;
答案 1 :(得分:1)
未找到API包'remote_socket'或调用'Resolve()'表示已请求InetAddress进行名称解析并且未找到未定API(remote_socket.Resolve)。
remote_socket API作为套接字可信测试程序的一部分启用。
无论如何,您的问题是我们还不支持在应用引擎运行时中解析IP地址(除了localhost等)。
直接使用urlfetch api的建议是一种解决方法。
答案 2 :(得分:0)
谢谢!
解决了......
URL url = new URL("https://www.google.com/accounts/ClientLogin");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
StringBuilder content = new StringBuilder();
content.append("Email=").append(URLEncoder.encode(_DEFAULT_USER, "UTF-8"));
content.append("&Passwd=").append(URLEncoder.encode(_DEFAULT_PASS, "UTF-8"));
content.append("&service=").append(URLEncoder.encode("ah", "UTF-8"));
OutputStream outputStream = urlConnection.getOutputStream();
outputStream.write(content.toString().getBytes("UTF-8"));
outputStream.close();
// Response....
int responseCode = urlConnection.getResponseCode();
InputStream inputStream;
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = urlConnection.getInputStream();
} else {
inputStream = urlConnection.getErrorStream();
}