2015-04-29 52 views
0

我正在開發一個應用程序,因爲我曾經通過WebServices將我的聯繫號碼發送到服務器。在這裏我得到了我的聯繫人號碼數組,並且通過webservices發送了聯繫人數組。代碼,在Webservices上傳遞數組

NSString *myRequestString1 = [[NSString alloc] initWithFormat:@"contact_numbers=%@",MobiileArray ]; 


NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString1 UTF8String ] length: [ myRequestString1 length ] ]; 
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:@"http://myproject.in/myproject-contacts.php"]]; 

[request setHTTPMethod: @"POST"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; 
[request setHTTPBody: myRequestData]; 
NSURLResponse *response; 
NSError *err; 
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err]; 
NSError* error; 
NSMutableArray* result = [NSJSONSerialization JSONObjectWithData:returnData 
                 options:kNilOptions 

                  error:&error]; 
NSLog(@"result: %@", result); 

但響應爲空,我的代碼上的任何錯誤?你能否給我建議謝謝。

+0

什麼錯誤你會得到嗎? –

+1

錯誤結果:null –

+0

這可能聽起來很愚蠢,但你確定你的問題在客戶端?也許你的web服務沒有返回你所期望的。 –

回答

0

試試下面的解決方案..!

替換這個代碼行

NSString *myRequestString1 = [[NSString alloc] initWithFormat:@"contact_numbers=%@",MobiileArray ]; 
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString1 UTF8String ] length: [ myRequestString1 length ] ]; 

//使用這個代碼行

//NSDictionary *dict = [NSDictionary dictionaryWithObject: MobiileArray forKey:@"contact_numbers"]; 

NSString* myRequestString1 = [MobiileArray JSONRepresentation]; 
NSData *myRequestData = [myRequestString1 dataUsingEncoding:NSUTF8StringEncoding]; 

//把

[request setValue:@"application/json" forHTTPHeaderField:@"content-type"]; 

檢查它...

+0

謝謝你,contact_numbers不是關鍵,它是發送數據到webservices的參數 –

+0

我修改了答案...現在檢查它..! – Vidhyanand

+0

它傳遞null的同樣的問題@ vidhyanand900 –