求助,有没有谁知道下面这段java代码用python怎么重写,感激不尽
privatelonggetFileSize(StringsURL){intnFileLength=-1;URLurl=newURL(sURL);HttpURLConne...
private long getFileSize(String sURL) {
int nFileLength = -1;
URL url = new URL(sURL);
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setRequestProperty("User-Agent", "Internet Explorer");
int responseCode = httpConnection.getResponseCode();
if (responseCode >= 400) {
return -2;
}
String sHeader;
for (int i = 1;; i++) {
sHeader = httpConnection.getHeaderFieldKey(i);
if (sHeader != null) {
if (sHeader.equals("Content-Length")) {
nFileLength = Integer.parseInt(httpConnection.getHeaderField(sHeader));
break;
}
} else
break;
}
} 展开
int nFileLength = -1;
URL url = new URL(sURL);
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setRequestProperty("User-Agent", "Internet Explorer");
int responseCode = httpConnection.getResponseCode();
if (responseCode >= 400) {
return -2;
}
String sHeader;
for (int i = 1;; i++) {
sHeader = httpConnection.getHeaderFieldKey(i);
if (sHeader != null) {
if (sHeader.equals("Content-Length")) {
nFileLength = Integer.parseInt(httpConnection.getHeaderField(sHeader));
break;
}
} else
break;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询