2010-08-03 45 views
0

http://something.php?ownerID=13&view=userAgreement 我需要兩個變量傳遞給這個.. 如何傳遞這些我正在申報OWNERID在我的配置播放列表13,我能夠得到它,如何設置「視圖= useragreement」字符串中查看變量的....如何將參數傳遞給URL(PHP文件)

任何機構可以告訴我的示例代碼.. 我使用像

NSString* termsURL = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"termsURL"]; 
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@%@%@", termsURL, @"?ownerID=", ownerID,@"?view=",userAgreement]]; 

,但不工作,我檢查解析成功與否與此網址,但是失敗...

回答

0

從我的應用程序直接採取代碼。它適用於需要

NSString *post = [NSString stringWithFormat:@"ownerID=13&view=userAgreement"]; 

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

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

//set up the request to the website 
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 

[request setURL:[NSURL URLWithString:@"http://something.php"]]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

[request setHTTPBody:postData]; 
NSError *error; 
NSURLResponse *response; 

NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
NSString *result3=[[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]autorelease]; 
+0

正是我想要的,笏是錯我的代碼以及一個 – 2010-08-03 17:58:54

+0

你將有兩個「?」在錯誤的PHP字符串中,你只能在開頭有一個。你真的沒有給出足夠的代碼讓我看看還有什麼可能會出錯的。再次,雖然只是複製粘貼我的代碼在你的項目和格式的「後」字符串,它會工作 – 2010-08-03 18:20:02