如何通过iphone中的ASIHTTPRequest发布数据

时间:2011-07-23 12:04:24

标签: iphone objective-c asihttprequest

如何通过ASIHTTPRequest发布表单字段数据(姓名,电子邮件,语音,分数)。我正在使用json webservices。

1 个答案:

答案 0 :(得分:1)

试试这个,在标题类中指定变量

ASIFormDataRequest * requestASI;

你的.m文件中的

 -(void)startASIRequest {

NSString *strUrl = [NSString stringWithFormat:@"http://your url"];

NSURL *url = [NSURL URLWithString:strUrl];

[self setRequestASI:[ASIFormDataRequest requestWithURL:url]];

[requestASI setDelegate:self];

[requestASI setRequestMethod:@"POST"];

[requestASI setPostValue:@"1" forKey:@"name"];

 [requestASI setDidFailSelector:@selector(uploadFailed:)];

[requestASI setDidFinishSelector:@selector(uploadFinished:)];

[requestASI startAsynchronous];


   - (void)uploadFinished:(ASIHTTPRequest *)theRequest {

NSLog(@"registerFinished %@",[theRequest responseString]);

  }

  - (void)uploadFailed:(ASIHTTPRequest *)theRequest {

NSLog(@"registerFailed %@", [theRequest error]);

}