Android doFetch住在哪里?
我正在浏览OwnCloud Android客户端的源代码,不知道从哪里调用doFetch。我尝试使用Github搜索,但找不到它的定义。我也试着检查了一些DEP,但失败了。这就是它被调用的地方 有人能帮我找出这个函数的定义在哪里吗?这里:Android doFetch住在哪里?,android,Android,我正在浏览OwnCloud Android客户端的源代码,不知道从哪里调用doFetch。我尝试使用Github搜索,但找不到它的定义。我也试着检查了一些DEP,但失败了。这就是它被调用的地方 有人能帮我找出这个函数的定义在哪里吗?这里: https://github.com/irccloud/android/blob/082f45918b44da5466238e1287bab5df794fc9fb/src/com/irccloud/android/NetworkConnection.java
https://github.com/irccloud/android/blob/082f45918b44da5466238e1287bab5df794fc9fb/src/com/irccloud/android/NetworkConnection.java#L2378
在Chrome上使用Ctrl-F进行查找。它位于同一文件NetworkConnection.java中
private String doFetch(URL url, String postdata, String sk, String token) throws Exception {
HttpURLConnection conn = null;
Proxy proxy = null;
String host = null;
int port = -1;
if(Build.VERSION.SDK_INT <11) {
Context ctx = IRCCloudApplication.getInstance().getApplicationContext();
if(ctx != null) {
host = android.net.Proxy.getHost(ctx);
port = android.net.Proxy.getPort(ctx);
}
} else {
host = System.getProperty("http.proxyHost", null);
try {
port = Integer.parseInt(System.getProperty("http.proxyPort", "8080"));
} catch (NumberFormatException e) {
port = -1;
}
}
if(host != null && host.length() > 0 && !host.equalsIgnoreCase("localhost") && !host.equalsIgnoreCase("127.0.0.1") && port > 0) {
InetSocketAddress proxyAddr = new InetSocketAddress(host, port);
proxy = new Proxy(Proxy.Type.HTTP, proxyAddr);
}
if(host != null && host.length() > 0 && !host.equalsIgnoreCase("localhost") && !host.equalsIgnoreCase("127.0.0.1") && port > 0) {
Crashlytics.log(Log.DEBUG, TAG, "Requesting: " + url + " via proxy: " + host);
} else {
Crashlytics.log(Log.DEBUG, TAG, "Requesting: " + url);
}
if (url.getProtocol().toLowerCase().equals("https")) {
HttpsURLConnection https = (HttpsURLConnection)((proxy != null)?url.openConnection(proxy):url.openConnection(Proxy.NO_PROXY));
if(url.getHost().equals(IRCCLOUD_HOST))
https.setSSLSocketFactory(IRCCloudSocketFactory);
conn = https;
} else {
conn = (HttpURLConnection)((proxy != null)?url.openConnection(proxy):url.openConnection(Proxy.NO_PROXY));
}
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setUseCaches(false);
conn.setRequestProperty("User-Agent", useragent);
conn.setRequestProperty("Accept", "application/json");
if(sk != null)
conn.setRequestProperty("Cookie", "session="+sk);
if(token != null)
conn.setRequestProperty("x-auth-formtoken", token);
if(postdata != null) {
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
OutputStream ostr = null;
try {
ostr = conn.getOutputStream();
ostr.write(postdata.getBytes());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (ostr != null)
ostr.close();
}
}
BufferedReader reader = null;
String response = "";
try {
ConnectivityManager cm = (ConnectivityManager)IRCCloudApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if(ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) {
Crashlytics.log(Log.DEBUG, TAG, "Loading via WiFi");
} else {
Crashlytics.log(Log.DEBUG, TAG, "Loading via mobile");
}
} catch (Exception e) {
}
try {
if(conn.getInputStream() != null) {
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()), 512);
}
} catch (IOException e) {
if(conn.getErrorStream() != null) {
reader = new BufferedReader(new InputStreamReader(conn.getErrorStream()), 512);
}
}
if(reader != null) {
response = toString(reader);
reader.close();
}
conn.disconnect();
return response;
}
private String doFetch(URL、String postdata、String sk、String token)引发异常{
HttpURLConnection conn=null;
Proxy=null;
字符串host=null;
int端口=-1;
if(Build.VERSION.SDK_INT 0&&!host.equalsIgnoreCase(“localhost”)&&&!host.equalsIgnoreCase(“127.0.0.1”)&&port>0){
InetSocketAddress proxyAddr=新的InetSocketAddress(主机、端口);
proxy=新代理(proxy.Type.HTTP,proxyAddr);
}
if(host!=null&&host.length()>0&&!host.equalsIgnoreCase(“localhost”)&&!host.equalsIgnoreCase(“127.0.0.1”)&&port>0){
log(log.DEBUG,标记为“请求:+url+”,通过代理:+host);
}否则{
log(log.DEBUG,标记“请求:”+url);
}
if(url.getProtocol().toLowerCase().equals(“https”)){
HttpsURLConnection https=(HttpsURLConnection)((proxy!=null)?url.openConnection(proxy):url.openConnection(proxy.NO_proxy));
if(url.getHost().equals(IRCCLOUD\u HOST))
https.setsslssocketfactory(ircloudsocketfactory);
conn=https;
}否则{
conn=(HttpURLConnection)((proxy!=null)?url.openConnection(proxy):url.openConnection(proxy.NO_proxy));
}
连接设置连接超时(5000);
连接设置读取超时(5000);
conn.SETUSECHACHES(假);
conn.setRequestProperty(“用户代理”,useragent);
conn.setRequestProperty(“接受”、“应用程序/json”);
if(sk!=null)
conn.setRequestProperty(“Cookie”,“session=“+sk”);
if(令牌!=null)
conn.setRequestProperty(“x-auth-formtoken”,令牌);
if(postdata!=null){
conn.setRequestMethod(“POST”);
连接设置输出(真);
conn.setRequestProperty(“内容类型”、“应用程序/x-www-form-urlencoded”);
OutputStream ost=null;
试一试{
ostr=conn.getOutputStream();
write(postdata.getBytes());
}捕获(例外e){
e、 printStackTrace();
}最后{
如果(ostr!=null)
ost.close();
}
}
BufferedReader reader=null;
字符串响应=”;
试一试{
ConnectivityManager cm=(ConnectivityManager)ircloudApplication.getInstance().getSystemService(Context.CONNECTIVITY_服务);
NetworkInfo ni=cm.getActiveNetworkInfo();
if(ni!=null&&ni.getType()==ConnectivityManager.TYPE\u){
Crashlytics.log(log.DEBUG,标记“通过WiFi加载”);
}否则{
log(log.DEBUG,标记“通过移动设备加载”);
}
}捕获(例外e){
}
试一试{
如果(连接getInputStream()!=null){
reader=新的BufferedReader(新的InputStreamReader(conn.getInputStream()),512);
}
}捕获(IOE异常){
如果(连接getErrorStream()!=null){
reader=新的BufferedReader(新的InputStreamReader(conn.getErrorStream()),512);
}
}
if(读卡器!=null){
响应=toString(读卡器);
reader.close();
}
连接断开();
返回响应;
}
np。。有时也会发生