在我的应用程序中,我发送了一个ASI HTTP post请求,所以我的用户可以将评论发布到我的Web服务但是我在发送请求时遇到了一些麻烦似乎总是失败我确定这是一个简单的错误我看着它,但它驱使我做了。
我的创建评论课程如下:
-(void)Submit
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://furious-ice-356.heroku.com/places/%@/reviews.xml",self.identifier]];
//[NSURL URLWithString:[NSString stringWithFormat:@"https://furious-ice-356.heroku.com///places/%@/reviews.xml",self.identifier]];
self.bestnight.text = @"Monday";
ASIFormDataRequest *request1 = [ASIFormDataRequest requestWithURL:url];
[request1 setUsername:self.username];
[request1 setPassword:self.password];
[request1 setRequestMethod:@"POST"];
[request1 setPostValue:self.bestnight.text forKey:@"review[best-night]"];
[request1 setPostValue:self.comments.text forKey:@"review[comments]"];
[request1 setPostValue:self.rating.text forKey:@"review[rating]"];
[request1 setDelegate:self];
[request1 startAsynchronous];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"FINISH Response received: %@", [request responseString]);
UIAlertView * av = [[[UIAlertView alloc] initWithTitle:@"Thank You" message:@"Your review was successfully posted. Thank You for making our App Better." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];
[av show];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"FAILED Response received: %@", [request responseString]);
}
答案 0 :(得分:2)
尝试添加:
[request setShouldPresentCredentialsBeforeChallenge:NO];
或者,如果这不起作用,尝试调用相同但传递'YES'。另外,正如其他人所说,仔细检查您的用户名/密码。