2012-05-22 65 views
0

我有下面的代碼張貼數據到Web服務器,但它給了我零響應,我有多個數據,他們分別是: -如何發佈多個數據到網絡服務器

date, 
rig, 
driller, 
offsider-1, 
offsider-2, 
shift 
, 
project, 
supervisoremail, 
geologistemail, 

comments, 


plants[0][name-id], 
plants[0][start-usage], 
plants[0][end-usage], 

consumables[0][category], 
consumables[0][name-id], 
consumables[0][used], 
consumables[0][code], 
consumables[0][description], 

我有權發佈此數據和我用這個代碼張貼,但它不適合我。請幫助我。

NSURL *url=[NSURL URLWithString:@"http://www.mydor.com.au/staff/dor/idorInsert"]; 
    NSString *post =[[NSString alloc]initWithFormat:@"date=15/08/2012&rig=53&driller=207&offsider-1=131&offsider- 2=236&shift=day&project=24&supervisoremail=24&geologistemail=24&comments=&plants[0][name- id]=286&plants[0][start-usage]=1.0&plants[0][end-usage]=0.0"]; 
    NSLog(post); 
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
    [request setURL:url]; 
    [request setHTTPMethod:@"POST"]; 
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
    [request setHTTPBody:postData]; 
    [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]]; 

    NSError *error; 
    NSURLResponse *response; 
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
    NSLog(@"here u re"); 
    NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; 
    NSLog(@"here also called"); 
    NSLog(@"%@",data) 

在此先感謝。

+0

你確定你的「發佈」字符串是真的嗎?它看起來更像是一個應該追加到URL的查詢字符串。 – sc0rp10n

+0

嗨,我不知道,我只是通過從其他網站引用它使用它登錄Web服務,我使用字符串username = xx&password = xyz,它的工作原理。對於它我不知道如何實現數據 – Jprat

回答

0

幾乎所有的工作包括.NET與iOS。看看我編寫和使用的網絡類(基於AFNetworking)的here。我更喜歡使用常規aspx表單而不是asmx Web服務。我這樣做是因爲我不想公開任何Web方法來窺探訪問者,並且在返回aspx表單中的任何內容之前使用API​​密鑰檢查。如果您需要我,我可以向您發送示例.NET代碼(用VB.NET編寫)。

+0

你能告訴我哪種方法適合我從你的建議的方法,我可以使用我的代碼,我發佈了幾乎沒有變化,或者我必須改變你的方式。請告訴我什麼是我的方法錯誤,我發送數據以錯誤的方式或錯誤在哪裏。請指導。謝謝。 – Jprat

+0

我引用的網絡類將被用來代替NSMutableURLRequest和NSURLConnection。網絡類中的方法非常明瞭。 –