@@ -35,6 +35,7 @@ public class Request {
3535 private URLConnection conn = null ;
3636 private Proxy HttpProxy ;
3737 private java .net .URL url ;
38+ private java .net .URL orgURL ;
3839 private int connectionTimeout = 0 ;
3940 private int readTimeout = 0 ;
4041 private boolean useCache = false ;
@@ -77,7 +78,7 @@ public boolean verify(String hostname, SSLSession session) {
7778
7879
7980 public Request clone (){
80- Request request = new Request (url );
81+ Request request = new Request (orgURL );
8182 request .HttpProxy = HttpProxy ;
8283 request .connectionTimeout = connectionTimeout ;
8384 request .readTimeout = readTimeout ;
@@ -107,13 +108,7 @@ public Request(String url){
107108 * @param httpProxy Proxy server
108109 */
109110 public Request (String url , String httpProxy ) {
110- try {
111- this .url = new java .net .URL (url );
112- setProxy (httpProxy );
113- initHeaders ();
114- }
115- catch (Exception e ) {
116- }
111+ this (getURL (url ), httpProxy );
117112 }
118113
119114
@@ -134,12 +129,21 @@ public Request(java.net.URL url){
134129 * @param httpProxy Proxy server
135130 */
136131 public Request (java .net .URL url , String httpProxy ){
137- this .url = url ;
132+ this .url = orgURL = url ;
138133 setProxy (httpProxy );
139134 initHeaders ();
140135 }
141136
142137
138+ private static java .net .URL getURL (String url ){
139+ try {
140+ return new java .net .URL (url );
141+ }
142+ catch (Exception e ) {
143+ return null ;
144+ }
145+ }
146+
143147 //**************************************************************************
144148 //** initHeaders
145149 //**************************************************************************
@@ -155,18 +159,37 @@ private void initHeaders(){
155159 }
156160
157161
162+ public void setURL (java .net .URL url ){
163+ this .url = url ;
164+ this .orgURL = url ;
165+ }
166+
158167 //**************************************************************************
159168 //** getURL
160169 //**************************************************************************
161- /** Used to return the URL used to make the request. Note that the URL
162- * may be different from the URL used to invoke this class if the request
170+ /** Returns the URL used to make the request. Note that the URL may be
171+ * different from the URL used to invoke this class if the request
163172 * encounters a redirect. See setNumRedirects() for more information.
173+ * Use the getInitialURL() to get the original URL used to instantiate this
174+ * class.
164175 */
165176 public java .net .URL getURL (){
166177 return url ;
167178 }
168179
169180
181+ //**************************************************************************
182+ //** getInitialURL
183+ //**************************************************************************
184+ /** Returns the URL used to instantiate this class. This URL may be
185+ * different from the URL used to execute the request. See getURL() for
186+ * more information.
187+ */
188+ public java .net .URL getInitialURL (){
189+ return orgURL ;
190+ }
191+
192+
170193 //**************************************************************************
171194 //** getResponse
172195 //**************************************************************************
@@ -1024,7 +1047,7 @@ public String toString(){
10241047 StringBuffer out = new StringBuffer ();
10251048 //System.out.println("Request Header");
10261049 //System.out.println("------------------------------------------------");
1027-
1050+ out . append ( url + " \r \n " );
10281051 java .util .Map <String ,List <String >> requestHeaders = getRequestHeaders ();
10291052 if (requestHeaders !=null ){
10301053 java .util .Iterator it = requestHeaders .keySet ().iterator ();
0 commit comments