1 2 3 | import com.alibaba.appengine.api.fetchurl.FetchUrlService; import com.alibaba.appengine.api.fetchurl.FetchUrlServiceFactory; FetchUrlService fetchUrlService = FetchUrlServiceFactory.getFetchUrlService(); |
1 2 3 4 5 6 7 8 9 | /** * 对指定的url,发起HTTP GET请求,获取HTTP相应的内容 * @param url HTTP URL地址 不能为null * @return 响应内容 * @throws FetchUrlNotAllowedException url为非HTTP协议、非白名单域名 * @throws FetchUrlException 操作出错,如连接FetchUrl Server失败 * @throws NullPointerException url参数为null */ String get(String url); |
1 2 3 4 5 6 7 8 9 10 | /** * @param url HTTP URL地址 不能为null * @param requestParameters 请求参数Map如果为null,则表示空参数 * @return 响应内容 * @throws FetchUrlNotAllowedException url为非HTTP协议、非白名单域名 * @throws FetchUrlException 出错,如连接FetchUrl Server失败 * @throws NullPointerException url参数为null */ * 对指定的url,发起HTTP POST请求,获取HTTP相应的内容,请求参数编码默认为 UTF- 8 String post(String url, Map requestParameters); |
1 2 3 4 5 6 7 8 9 10 11 | /** * 对指定的url,发起HTTP POST请求,获取HTTP相应的内容 * @param url HTTP URL地址 不能为null * @param requestParameters 请求参数Map如果为null,则表示空参数 * @param parameterCharset 请求参数的字符编码,取值范围 UTF-8 | GBK | ISO-8859-1,默认值为 UTF-8 * @return 响应内容 * @throws FetchUrlNotAllowedException url为非HTTP协议、非白名单域名 * @throws FetchUrlException 出错,如连接FetchUrl Server失败 * @throws NullPointerException url参数为null */ String post(String url, Map requestParameters, String parameterCharset); |
1 2 3 4 5 6 7 8 9 10 11 | /** * 对指定的url,发起HTTP GET请求,获取HTTP相应的内容 * * @param url HTTP URL地址 不能为 null * @return 响应内容 * @throws FetchUrlNotAllowedException url为非HTTP协议、非白名单域名 * @throws FetchUrlException 操作出错,如连接FetchUrl Server失败 * @throws NullPointerException * @since 1.1 . 1 * / byte [] getBytes(String url); |
为了规范TAE中isv对淘宝站内站外的域名访问情况,后面FetchUrl服务的全局白名单只留下下面四个:
eco.taobao.com
login.taobao.com
a.tbcdn.cn/app/sns/*
pin.aliyun.com
img.taobaocdn.com
api.weibo.com
oauth.taobao.com
其它需要访问的域名配置到对应应用的白名单中,需要在TAE控制台里申请添加。申请添加的域名个数限制为5个,审核时间在一个工作日左右。
注意:Java不再支持使用httpclient、httpconnection等调用站外;Php不再支持使用curl函数调用站外。TAE中top接口调用不在此限制,如有对应的站外调用需求,请改为使用fetchurl服务.