Browse Source

Fix incorrect param urlencode bug #26

Ben Hsieh 8 years ago
parent
commit
cc52ad4ba0

+ 5
- 19
src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java View File

160
         RNFetchBlobConfig config = new RNFetchBlobConfig(options);
160
         RNFetchBlobConfig config = new RNFetchBlobConfig(options);
161
 
161
 
162
         try {
162
         try {
163
-            Uri uri = Uri.parse(url);
164
             AsyncHttpClient req = new AsyncHttpClient();
163
             AsyncHttpClient req = new AsyncHttpClient();
165
 
164
 
166
-            // set params
167
-            RequestParams params = new RequestParams();
168
             AbstractHttpEntity entity = null;
165
             AbstractHttpEntity entity = null;
169
 
166
 
170
-            // set params
171
-            for (String paramName : uri.getQueryParameterNames()) {
172
-                params.put(paramName, uri.getQueryParameter(paramName));
173
-            }
174
-
175
             // set headers
167
             // set headers
176
             ReadableMapKeySetIterator it = headers.keySetIterator();
168
             ReadableMapKeySetIterator it = headers.keySetIterator();
177
             while (it.hasNextKey()) {
169
             while (it.hasNextKey()) {
212
             // send request
204
             // send request
213
             switch(method.toLowerCase()) {
205
             switch(method.toLowerCase()) {
214
                 case "get" :
206
                 case "get" :
215
-                    req.get(url, params, handler);
207
+                    req.get(url, handler);
216
                     break;
208
                     break;
217
                 case "post" :
209
                 case "post" :
218
                     req.post(this.getReactApplicationContext(), url, entity, "octet-stream", handler);
210
                     req.post(this.getReactApplicationContext(), url, entity, "octet-stream", handler);
221
                     req.put(this.getReactApplicationContext(), url, entity, "octet-stream",handler);
213
                     req.put(this.getReactApplicationContext(), url, entity, "octet-stream",handler);
222
                     break;
214
                     break;
223
                 case "delete" :
215
                 case "delete" :
224
-                    req.delete(url, params, handler);
216
+                    req.delete(url, handler);
225
                     break;
217
                     break;
226
             }
218
             }
227
         } catch(Exception error) {
219
         } catch(Exception error) {
235
 
227
 
236
         RNFetchBlobConfig config = new RNFetchBlobConfig(options);
228
         RNFetchBlobConfig config = new RNFetchBlobConfig(options);
237
         try {
229
         try {
238
-            Uri uri = Uri.parse(url);
230
+
239
             AsyncHttpClient req = new AsyncHttpClient();
231
             AsyncHttpClient req = new AsyncHttpClient();
240
 
232
 
241
-            // set params
242
-            RequestParams params = new RequestParams();
243
             HttpEntity entity = null;
233
             HttpEntity entity = null;
244
-            // set params
245
-            for (String paramName : uri.getQueryParameterNames()) {
246
-                params.put(paramName, uri.getQueryParameter(paramName));
247
-            }
248
 
234
 
249
             // set headers
235
             // set headers
250
             if(headers != null) {
236
             if(headers != null) {
307
             // send request
293
             // send request
308
             switch(method.toLowerCase()) {
294
             switch(method.toLowerCase()) {
309
                 case "get" :
295
                 case "get" :
310
-                    req.get(url, params, handler);
296
+                    req.get(url, handler);
311
                     break;
297
                     break;
312
                 case "post" :
298
                 case "post" :
313
                     req.post(this.getReactApplicationContext(), url, entity, "multipart/form-data; charset=utf8", handler);
299
                     req.post(this.getReactApplicationContext(), url, entity, "multipart/form-data; charset=utf8", handler);
316
                     req.put(this.getReactApplicationContext(), url, entity, "multipart/form-data",handler);
302
                     req.put(this.getReactApplicationContext(), url, entity, "multipart/form-data",handler);
317
                     break;
303
                     break;
318
                 case "delete" :
304
                 case "delete" :
319
-                    req.delete(url, params, handler);
305
+                    req.delete(url, handler);
320
                     break;
306
                     break;
321
             }
307
             }
322
         } catch(Exception error) {
308
         } catch(Exception error) {

+ 4
- 3
src/ios/RNFetchBlob/RNFetchBlob.m View File

61
                   form:(NSArray *)form
61
                   form:(NSArray *)form
62
                   callback:(RCTResponseSenderBlock)callback)
62
                   callback:(RCTResponseSenderBlock)callback)
63
 {
63
 {
64
-    
64
+    NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
65
     // send request
65
     // send request
66
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
66
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
67
                                     initWithURL:[NSURL
67
                                     initWithURL:[NSURL
68
-                                                 URLWithString: url]];
68
+                                                 URLWithString: encodedUrl]];
69
     
69
     
70
     NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[ RNFetchBlobNetwork normalizeHeaders:headers]];
70
     NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[ RNFetchBlobNetwork normalizeHeaders:headers]];
71
     
71
     
141
                   headers:(NSDictionary *)headers
141
                   headers:(NSDictionary *)headers
142
                   body:(NSString *)body callback:(RCTResponseSenderBlock)callback)
142
                   body:(NSString *)body callback:(RCTResponseSenderBlock)callback)
143
 {
143
 {
144
+    NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
144
     // send request
145
     // send request
145
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
146
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
146
                                     initWithURL:[NSURL
147
                                     initWithURL:[NSURL
147
-                                                 URLWithString: url]];
148
+                                                 URLWithString: encodedUrl]];
148
     
149
     
149
     NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[RNFetchBlobNetwork normalizeHeaders:headers]];
150
     NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[RNFetchBlobNetwork normalizeHeaders:headers]];
150
     // move heavy task to another thread
151
     // move heavy task to another thread