0

我正在尝试从我的手机在 Android 中将数据发布到 Google 文档,但是每当我发送请求时,我都会返回一个奇怪的 html(不是错误)页面。

如果我将在设备上生成的相同 url 复制/粘贴到我的桌面浏览器中,它就可以正常工作(我使用的是 Postman,所以它不是 Post/Get 动词错误)。

我的猜测是 Google 文档将我的设备识别为 Android 设备并将我的请求重定向到 Android google 文档页面。有什么办法可以阻止这种情况发生?

这是我的代码:

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.
4

2 回答 2

0

我猜他们通过用户代理字符串确定它是否是电话。找到适合您的浏览器的用户代理,然后使用以下链接进行更改。

更改用户代理

于 2012-10-14T18:50:11.503 回答
0

所以问题在于权限,而不是用户代理。我设置了对任何人的访问权限,但没有设置“任何人,甚至是匿名的”。

于 2012-10-14T19:06:33.747 回答