2
我想在NSMutableURLRequest加載一個網址如下GET請求:GET請求使用太多的參數 - 的iOS
NSString *serverAddress = [NSString stringWithFormat:@"http://test.us.to:8080/api/offers?altId=%@&provider=%@&otherId=%@&tenantId=%@&createdAt=%@&otherOfferId=%@&postId=%@&pageId=%@&sourceUrl=%@&name=%@&description=%@&text=%@&category=%@&caption=%@&startTime=%@&expirationTime=%@&minPurchase=%@&numPurchases=%@&value=%@&percent=%@&count=%@¤cy=%@&terms=%@&campaignId=%@&partnerId=%@&tenantIdAtPartner=%@&issuerName=%@&claimLimit=%@&onePerUser=%@&emailTemplateFile=%@",@"test",@"Facebook",@"",@"test",@"null",@"test",@"",@"",@"http://test.us.to/offers/harvester_summer13.html",@"Harvester",@"Harvester 2for1 TakeAway",@"Enjoy!",@"voucher",@"Harvester 2for1 TakeAway",[NSNumber numberWithInt:0],@"test",[NSNumber numberWithInt:0],[NSNumber numberWithInt:0],@"1000",[NSNumber numberWithInt:0],[NSNumber numberWithInt:0],@"GBP",@"",[NSNumber numberWithInt:1259],@"null" ,@"null" ,@"null",[NSNumber numberWithInt:100],[NSNumber numberWithBool:false],@"templates/test.vm"];
NSURL *url = [NSURL URLWithString:[serverAddress urlEncodeUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:15.0];
NSString *authStr = [NSString stringWithFormat:@"%@:%@", @"testuser", @"testpwd"];
NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodedStringWithOptions:0]];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
[request setHTTPMethod: @"GET"];
NSError *requestError;
NSURLResponse *urlResponse = nil;
NSData *response1 = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];
的NSLog(@ 「輸出數據%@」,響應1);
我猜我加載使用URL字符串太多的參數。有沒有更好的方法來傳遞GET請求的參數?電流輸出爲空的響應1
你怎麼知道你有太多的參數? – rmaddy
GET請求沒有限制嗎? 256個字符? –
它看起來像你編碼整個serverAddress字符串。你不應該只是在URL地址之後編碼參數嗎? – Scampbell