0

Has anyone released code to show the full HTTP request/response headers, any intermediate redirects, and any cookie data for the Android HttpURLConnection? This would be similar to Firefox Web Console

I roughly know how to write this myself, but 1) it's a non-trivial amount of code 2) it's tricky to get this kind of code to work in all instances. So i'm interested in finding a readymade solution. I know how to tcpdump the emulator, but I'm searching for code to print this information into the Android Log class for really quick runtime debugging.

Hamy
  • 20,662
  • 15
  • 74
  • 102

1 Answers1

0

for header fields

    URL url = new URL(str_url);
         HttpURLConnection conection = (HttpURLConnection) url.openConnection();
         conection.setConnectTimeout(TIMEOUT_SOCKET);
         conection.setReadTimeout(TIMEOUT_CONNECTION);
         conection.addRequestProperty("Accept-Encoding", "gzip");
         RedirectLocations locations = new RedirectLocations();

         // here u get all header fields and properties write it in logs
         conection.getHeaderFields();
         conection.getRequestProperties();
    //      conection.getOutputStream().write(buffer);
        // download the file
         InputStream is = conection.getInputStream();

         // This is file path were a; quiz data will get saved. 

        // String file_path = context.getDir(folder,Activity.MODE_PRIVATE).getAbsolutePath();
         return unzip(is,save_file_path);

for redirects

link

after u get response, again u ve to look for header fields

Community
  • 1
  • 1
Sush
  • 3,864
  • 2
  • 17
  • 35
  • This doesn't show cookies, which are the primary item of interest for most redirect-heavy sites. Rereading my original question this may have been an unclear requirement, so I've updated the question to show that cookies are important – Hamy Dec 29 '13 at 06:23
  • For that you should use CooikeManagerSync, its globle in android. – Sush Dec 29 '13 at 06:29
  • I know how to program what I want :-) However, there are many small items that would make programming+debugging this take a good amount of time. I'm asking if anyone has taken the time to build something already – Hamy Dec 29 '13 at 06:37
  • many of them would have built but its according their requirement. – Sush Dec 29 '13 at 06:44
  • A decent http connection monitor code is a pretty general requirement. It's just tricky to do it properly. Any fool (myself included) can hack something together and either ignore or be ignorant of the bits that don't work – Hamy Dec 29 '13 at 06:52
  • then better i suggest encription based mechanism. – Sush Dec 29 '13 at 06:59