我試圖從我的手機在Android中向Google文檔發佈數據,但每當我發送請求時,我都會返回一個奇怪的html(而不是錯誤)頁面。在HTTP請求期間在Android中觸發桌面網頁
如果我將我在設備上生成的相同url複製/粘貼到我的桌面瀏覽器中,它工作得很好(我使用Postman,因此它不是Post/Get動詞錯誤)。
我的猜測是Google文檔會將我的設備識別爲Android設備,並將我的請求重定向到Android谷歌文檔頁面。任何方法來阻止這種情況發生?
這裏是我的代碼:
HttpClient httpclient = new DefaultHttpClient();
try {
HttpPost httppost = new HttpPost("https://docs.google.com/macros/exec?" +
"service=..." +
"&Param1=" + java.net.URLEncoder.encode(param1, "ISO-8859-1"));
Log.v("Request", httppost.getURI().toString());
InputStream localInputStream = httpclient.execute(httppost).getEntity().getContent();
byte bytes[] = new byte[20000];
localInputStream.read(bytes);
Log.e("LOG", new String(bytes));
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
這裏是頁我回去:
10-14 14:27:39.749: E/html(15814): <!DOCTYPE html>
10-14 14:27:39.749: E/html(15814): <html lang="en">
10-14 14:27:39.749: E/html(15814): <head>
10-14 14:27:39.749: E/html(15814): <meta charset="utf-8">
10-14 14:27:39.749: E/html(15814): <title>Welcome to Google Docs</title>
10-14 14:27:39.749: E/html(15814): <style type="text/css">
10-14 14:27:39.749: E/html(15814): html, body, div, h1, h2, h3, h4, h5, h6, p, img, dl,
10-14 14:27:39.749: E/html(15814): dt, dd, ol, ul, li, table, tr, td, form, object, embed,
10-14 14:27:39.749: E/html(15814): article, aside, canvas, command, details, fieldset,
10-14 14:27:39.749: E/html(15814): figcaption, figure, footer, group, header, hgroup, legend,
10-14 14:27:39.749: E/html(15814): mark, menu, meter, nav, output, progress, section, summary,
10-14 14:27:39.749: E/html(15814): time, audio, video {
10-14 14:27:39.749: E/html(15814): margin: 0;
10-14 14:27:39.749: E/html(15814): padding: 0;
10-14 14:27:39.749: E/html(15814): border: 0;
10-14 14:27:39.749: E/html(15814): }
10-14 14:27:39.749: E/html(15814): article, aside, details, figcaption, figure, footer,
10-14 14:27:39.749: E/html(15814): header, hgroup, menu, nav, section {
10-14 14:27:39.749: E/html(15814): display: block;
10-14 14:27:39.749: E/html(15814): }
10-14 14:27:39.749: E/html(15814): html {
10-14 14:27:39.749: E/html(15814): font: 81.25% arial, helvetica, sans-serif;
10-14 14:27:39.749: E/html(15814): background: #fff;
10-14 14:27:39.749: E/html(15814): color: #333;
10-14 14:27:39.749: E/html(15814): line-height: 1;
10-14 14:27:39.749: E/html(15814): direction: ltr;
10-14 14:27:39.749: E/html(15814): }
... and so on.