Android URL Decode parseForHTTP(String str)

Here you can find the source of parseForHTTP(String str)

Description

This method reads a string and modifies it to support HTTP calls.

Parameter

Parameter Description
str a parameter

Return

A modified string with all special characters replaced with their valid equivalents.

Declaration

public static String parseForHTTP(String str) 

Method Source Code

//package com.java2s;

public class Main {
    /**// ww  w .ja  v  a2  s.c o  m
     * This method reads a string and modifies it to support HTTP calls. Certain characters which are used
     * as special characters in HTTP urls have to be converted to valid formats, and this method does the conversion.
     * @param str
     * @return A modified string with all special characters replaced with their valid equivalents.
     */
    public static String parseForHTTP(String str) {
        String result = "";

        for (int i = 0; i < str.length(); i++) {

            switch (str.charAt(i)) {
            case ' ':
                result += "%20";
                break;
            case '<':
                result += "%3C";
                break;
            case '>':
                result += "%3E";
                break;
            case '#':
                result += "%23";
                break;
            case '%':
                result += "%25";
                break;
            case '{':
                result += "%7B";
                break;
            case '}':
                result += "%7D";
            case '|':
                result += "%7E";
                break;
            case '\\':
                result += "%5B";
                break;
            case '^':
                result += "%5E";
                break;
            case '~':
                result += "%7E";
                break;
            case '[':
                result += "%5B";
                break;
            case ']':
                result += "%5D";
                break;
            case '`':
                result += "%60";
                break;
            case ';':
                result += "%3B";
                break;
            case '/':
                result += "%2F";
                break;
            case '?':
                result += "%3F";
                break;
            case ':':
                result += "%3A";
                break;
            case '@':
                result += "%40";
                break;
            case '=':
                result += "%3D";
                break;
            case '&':
                result += "%26";
                break;
            case '$':
                result += "%24";
                break;
            default:
                result += str.charAt(i);
                break;
            }

        }
        return result;
    }
}

Related

  1. decode(final String content, final String encoding)
  2. decode(String s)
  3. decodeUrl(String s)
  4. decodeUrl(String s)
  5. decodeUrlFormEncoded(String data)
  6. parseLastfmUrl(String url)
  7. parseUrl(String url)
  8. parseUrl(String url)
  9. parserTrackURL(String trackURL)