0

I'm trying to post data to Google docs from my phone in Android, but whenever I send the request, I get back a strange html (not error) page.

If I copy/paste the same url that I generate on the device into my desktop browser, it works just fine (I'm using Postman so it's not a Post/Get verb error).

My guess is that Google docs is recognizing my device as an Android device and redirecting my request to the Android google docs page. Any way to stop this from happening?

Here is my code:

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
        }

And here is the page I get back:

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.
Jason
  • 13,563
  • 15
  • 74
  • 125

2 Answers2

0

I'm guessing they determine if it's a phone by the user agent string. Find a user agent for the browser that worked for you and use the following link to change it.

Change user agent

Community
  • 1
  • 1
Nick
  • 676
  • 9
  • 22
0

So the issue was in permissions, not in user agent. I had set access to anyone, but not "anyone even anonymous."

Jason
  • 13,563
  • 15
  • 74
  • 125