浏览代码

Fix incorrect param urlencode bug #26

Ben Hsieh 8 年前
父节点
当前提交
cc52ad4ba0
共有 2 个文件被更改,包括 9 次插入22 次删除
  1. 5
    19
      src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java
  2. 4
    3
      src/ios/RNFetchBlob/RNFetchBlob.m

+ 5
- 19
src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java 查看文件

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

+ 4
- 3
src/ios/RNFetchBlob/RNFetchBlob.m 查看文件

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