/// <summary> /// Parses data from an HTML form that the client sends to /// the server using the HTTP POST method and the /// <i>application/x-www-form-urlencoded</i> MIME type. /// /// The data sent by the POST method contains key-value /// pairs. A key can appear more than once in the POST data /// with different values. However, the key appears only once in /// the hashtable, with its value being /// an array of strings containing the multiple values sent /// by the POST method. /// /// The keys and values in the hashtable are stored in their /// decoded form, so /// any + characters are converted to spaces, and characters /// sent in hexadecimal notation (like <i>%xx</i>) are /// converted to ASCII characters. /// </summary> /// <param name="len"> /// len an integer specifying the length, /// in characters, of the /// ServletInputStream /// object that is also passed to this /// method /// </param> /// <param name="input"> /// the ServletInputStream /// object that contains the data sent /// from the client /// </param> /// <returns>a Dictonary object built from the parsed key-value pairs</returns> /// <exception cref="ArgumentException">if the data sent by the POST method is invalid</exception> static public Dictionary <string, object> ParsePostData(int len, ServletInputStream input) { // XXX // should a length of 0 be an ArgumentException if (len <= 0) { return(new Dictionary <string, object>()); // cheap hack to return an empty hash } if (input == null) { throw new ArgumentException(); } // // Make sure we read the entire POSTed body. // char[] postedBytes = new char[len]; try { int offset = 0; do { int inputLen = input.Read(postedBytes, offset, len - offset); if (inputLen <= 0) { //string msg = lStrings.getString("err.io.short_read"); string msg = "Short Read"; throw new ArgumentException(msg); } offset += inputLen; } while ((len - offset) > 0); } catch (IOException e) { throw new ArgumentException(e.Message); } // XXX we shouldn't assume that the only kind of POST body // is FORM data encoded using ASCII or ISO Latin/1 ... or // that the body should always be treated as FORM data. // try { string postedBody = new string(postedBytes, 0, len); return(ParseQueryString(postedBody)); } catch (ArgumentException e) { // XXX function should accept an encoding parameter & throw this // exception. Otherwise throw something expected. throw new ArgumentException(e.Message); } }
/// <summary> /// Parses data from an HTML form that the client sends to /// the server using the HTTP POST method and the /// <i>application/x-www-form-urlencoded</i> MIME type. /// /// The data sent by the POST method contains key-value /// pairs. A key can appear more than once in the POST data /// with different values. However, the key appears only once in /// the hashtable, with its value being /// an array of strings containing the multiple values sent /// by the POST method. /// /// The keys and values in the hashtable are stored in their /// decoded form, so /// any + characters are converted to spaces, and characters /// sent in hexadecimal notation (like <i>%xx</i>) are /// converted to ASCII characters. /// </summary> /// <param name="len"> /// len an integer specifying the length, /// in characters, of the /// ServletInputStream /// object that is also passed to this /// method /// </param> /// <param name="input"> /// the ServletInputStream /// object that contains the data sent /// from the client /// </param> /// <returns>a Dictonary object built from the parsed key-value pairs</returns> /// <exception cref="ArgumentException">if the data sent by the POST method is invalid</exception> public static Dictionary<string, object> ParsePostData(int len, ServletInputStream input) { // XXX // should a length of 0 be an ArgumentException if (len <= 0) return new Dictionary<string, object>(); // cheap hack to return an empty hash if (input == null) { throw new ArgumentException(); } // // Make sure we read the entire POSTed body. // char[] postedBytes = new char[len]; try { int offset = 0; do { int inputLen = input.Read(postedBytes, offset, len - offset); if (inputLen <= 0) { //string msg = lStrings.getString("err.io.short_read"); string msg = "Short Read"; throw new ArgumentException(msg); } offset += inputLen; } while ((len - offset) > 0); } catch (IOException e) { throw new ArgumentException(e.Message); } // XXX we shouldn't assume that the only kind of POST body // is FORM data encoded using ASCII or ISO Latin/1 ... or // that the body should always be treated as FORM data. // try { string postedBody = new string(postedBytes, 0, len); return ParseQueryString(postedBody); } catch (ArgumentException e) { // XXX function should accept an encoding parameter & throw this // exception. Otherwise throw something expected. throw new ArgumentException(e.Message); } }