0

我正在尝试在 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 .

有任何想法吗?我完全迷路了...

4

3 回答 3

1

你可以使用不同的http客户端吗?比如这里推荐的:

client = new HttpClient(new SimpleHttpConnectionManager()); 

或者如何使用URLFetchService

根据this blog post,您需要:

“自定义连接管理器转换最终请求并将它们提供给 URL Fetch 服务,然后将响应反馈给 HttpClient。”

于 2012-10-03T14:59:05.363 回答
1

未找到 API 包 'remote_socket' 或调用 'Resolve()' 意味着已请求 InetAddress 进行名称解析,并且未找到不符合要求的 API (remote_socket.Resolve)。

remote_socket API 作为受信任的套接字测试程序的一部分启用。

无论如何,您的问题是我们尚不支持在应用程序引擎运行时中解析 IP 地址(本地主机等除外)。

直接使用 urlfetch api 的建议是一种解决方法。

于 2012-10-04T06:10:47.603 回答
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();
        }
于 2012-10-04T11:15:02.003 回答