http://something.php?ownerID=13&view=userAgreement 我需要传递两个变量到这个.. 我如何通过这些我在我的配置播放列表中声明ownerid到13并且我能够得到它,如何设置“view = useragreement”字符串来查看变量....
任何机构都可以给我看示例代码.. 我正在使用像
NSString* termsURL = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"termsURL"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@%@%@", termsURL, @"?ownerID=", ownerID,@"?view=",userAgreement]];
但是没有用,我正在检查解析是否成功与此网址但是失败...
答案 0 :(得分: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];