HTTPSを使用してAndroid上でWebページを取得しています(証明書を無視すると、自己署名と旧式の両方であるため、here - 私のサーバーではありません:))。AndroidがHTTPSページを切り捨てるようにする
私が定義されてきた私のUnsecureSSLSocketFactoryが言及した
public class MyHttpClient extends DefaultHttpClient {
public MyHttpClient() {
super();
final HttpParams params = getParams();
HttpConnectionParams.setConnectionTimeout(params,
REGISTRATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT);
ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT);
}
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
registry.register(new Scheme("https", new UnsecureSSLSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);
}
}
前述
topicに与えられた提案に基づいています。
私はその後、私は取得ページ約100行の後に切り捨てられるページをfecthする
public class HTTPHelper {
private final static String TAG = "HTTPHelper";
private final static String CHARSET = "ISO-8859-1";
public static final String USER_AGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)";
public static final String ACCEPT_CHARSET = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
public static final String ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
/**
* Sends an HTTP request
* @param url
* @param post
* @return
*/
public String sendRequest(String url, String post) throws ConnectionException {
MyHttpClient httpclient = new MyHttpClient();
HttpGet httpget = new HttpGet(url);
httpget.addHeader("User-Agent", USER_AGENT);
httpget.addHeader("Accept", ACCEPT);
httpget.addHeader("Accept-Charset", ACCEPT_CHARSET);
HttpResponse response;
try {
response = httpclient.execute(httpget);
} catch (Exception e) {
throw new ConnectionException(e.getMessage());
}
HttpEntity entity = response.getEntity();
try {
pageSource = convertStreamToString(entity.getContent());
} catch (Exception e) {
throw new ConnectionException(e.getMessage());
}
finally {
if (entity != null) {
try {
entity.consumeContent();
} catch (IOException e) {
throw new ConnectionException(e.getMessage());
}
}
}
httpclient.getConnectionManager().shutdown();
return pageSource;
}
/**
* Converts a stream to a string
* @param is
* @return
*/
private static String convertStreamToString(InputStream is)
{
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, CHARSET));
StringBuilder stringBuilder = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
} catch (IOException e) {
Log.d(TAG, "Exception in convertStreamToString", e);
} finally {
try {
is.close();
} catch (IOException e) {}
}
return stringBuilder.toString();
} catch (Exception e) {
throw new Error("Unsupported charset");
}
}
}
をこのクラスを使用しています。これは正確なポイントで切り捨てられ、 '_'(アンダースコア)の後に 'r'の文字が続きます。このページの最初のアンダースコアではありません。
私はそれがエンコードの問題かもしれないと思ったので、私はUTF-8とISO-8859-1の両方を試しましたが、まだ切り詰められています。 Firefoxでページを開くと、ISO-8851-1というエンコーディングが報告されます。
あなたが思っている場合は、Webページはhttps://ricarichiamoci.dsu.pisa.it/ あり、それはライン169で切り捨てられ、
ではなくfunction ChangeOffset(NewOffset) {
document.mainForm.last_record.value = NewOffset;
誰がなぜの考えを持っていなければなりません
function ChangeOffset(NewOffset) {
document.mainForm.last
ページは切り捨てられますか?