gpt4 book ai didi

java.net.InetAddress 不适用于 GAE 免费层

转载 作者:行者123 更新时间:2023-12-01 12:37:46 27 4
gpt4 key购买 nike

我有需要使用 GAE 运行的代码,

public class RootServerResource extends ServerResource {
@Get("json")
public String represent() {
String client = getRequest().getClientInfo().getAddress();
InetAddress addr = null;
try {
addr = InetAddress.getByName(client);
} catch (UnknownHostException e) {
e.printStackTrace();
}
String domain = addr.getHostName();
return "hello, world (from the cloud!), your client domain is: " + domain;
}
}

但它抛出:

Caused by: com.google.apphosting.api.ApiProxy$FeatureNotEnabledException: The Socket API will be enabled for this application once billing has been enabled in the admin console.

这个问题有解决方法吗?有没有办法使用 GAE 从 IP 获取域名? Socket API 不会被调用的某种方式。

最佳答案

域查找需要出站套接字,因此您需要让应用程序可以访问套接字 API。正如文档所说 Sockets API is only available for paid apps

解决这个问题的一种方法是使用具有 HTTP 接口(interface)的反向域查找服务,例如:http://www.statdns.com/api/ (请参阅本页末尾的获取反向 PTR 记录)。

关于java.net.InetAddress 不适用于 GAE 免费层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25418581/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com