| 41 | | |
| 42 | | /** |
| 43 | | * Random string for hazardous purpose |
| 44 | | */ |
| 45 | | private String sBoundary = "---------------------------" |
| 46 | | + DirectRequestPOST.randomString() |
| 47 | | + DirectRequestPOST.randomString() |
| 48 | | + DirectRequestPOST.randomString(); |
| 49 | | |
| 50 | | /** |
| 51 | | * URL to connect |
| 52 | | */ |
| 53 | | private URLConnection aURLConnection = null; |
| 54 | | |
| 55 | | /** |
| 56 | | * Output stream for the post |
| 57 | | */ |
| 58 | | private OutputStream aOutputStream = null; |
| 59 | | |
| 60 | | /** |
| 61 | | * Generate random strings |
| 62 | | * |
| 63 | | * @return a random string |
| 64 | | */ |
| 65 | | private static String randomString() { |
| 66 | | return Long.toString(DirectRequestPOST.aRandom.nextLong(), 36); |
| 67 | | } |
| 109 | | final URL aURL = new URL(sURL); |
| 110 | | this.aURLConnection = aURL.openConnection(); |
| 111 | | this.aURLConnection.setDoOutput(true); |
| 112 | | this.aURLConnection.setRequestProperty("Content-Type", |
| 113 | | "multipart/form-data; boundary=" + sBoundary); |
| 114 | | this.aURLConnection.setRequestProperty("Accept-Language", this.sLang); |
| | 73 | |
| | 74 | ClientHttpRequest request = new ClientHttpRequest(sURL); |
| | 75 | request.setLang(sLang); |
| | 76 | request.setParameters(mapOfParameter); |
| 116 | | if (null == this.aOutputStream) { |
| 117 | | this.aOutputStream = this.aURLConnection.getOutputStream(); |
| 118 | | } |
| 119 | | for (final String sName : this.mapOfParameter.keySet()) { |
| 120 | | final String sValue = this.mapOfParameter.get(sName); |
| 121 | | logger.trace("addParameter"); |
| 122 | | logger.debug("Name :" + sName + "."); |
| 123 | | logger.debug("Value :" + sValue + "."); |
| 124 | | logger.debug("--"); |
| 125 | | logger.debug(this.sBoundary); |
| 126 | | logger.debug("\r\n"); |
| 127 | | logger.debug("Content-Disposition: form-data; name=\""); |
| 128 | | logger.debug(sName); |
| 129 | | logger.debug('"'); |
| 130 | | logger.debug("\r\n"); |
| 131 | | logger.debug("\r\n"); |
| 132 | | logger.debug(sValue); |
| 133 | | logger.debug("\r\n"); |
| 134 | | // boundary |
| 135 | | this.aOutputStream.write("--".getBytes()); |
| 136 | | this.aOutputStream.write(this.sBoundary.getBytes()); |
| 137 | | // writeName |
| 138 | | this.aOutputStream.write("\r\n".getBytes()); |
| 139 | | this.aOutputStream.write("Content-Disposition: form-data; name=\"" |
| 140 | | .getBytes()); |
| 141 | | this.aOutputStream.write(sName.getBytes()); |
| 142 | | this.aOutputStream.write('"'); |
| 143 | | // newline |
| 144 | | this.aOutputStream.write("\r\n".getBytes()); |
| 145 | | // newline |
| 146 | | this.aOutputStream.write("\r\n".getBytes()); |
| 147 | | // writeln |
| 148 | | this.aOutputStream.write(sValue.getBytes()); |
| 149 | | this.aOutputStream.write("\r\n".getBytes()); |
| 150 | | } |
| 151 | | logger.debug("--"); |
| 152 | | logger.debug(this.sBoundary); |
| 153 | | logger.debug("--"); |
| 154 | | logger.debug("\r\n"); |
| 155 | | this.aOutputStream.write("--".getBytes()); |
| 156 | | this.aOutputStream.write(this.sBoundary.getBytes()); |
| 157 | | this.aOutputStream.write("--".getBytes()); |
| 158 | | this.aOutputStream.write("\r\n".getBytes()); |
| 159 | | this.aOutputStream.close(); |
| 160 | | |
| 161 | | InputStream is = aURLConnection.getInputStream(); |
| 162 | | |
| | 78 | InputStream is = request.post(); |