我在我的iOS应用程序中使用ASIHTTPRequest lib来向我的Rails 3 Web应用程序发出RESTful请求.我第一次尝试向我的网络应用程序发出POST请求时看到一个奇怪且有些一致的错误,但是POST请求在第二次尝试时工作正常.确切的错误是......
Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0xb513740 {NSUnderlyingError=0xb5135a0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)", NSLocalizedDescription=A connection failure occurred}
Run Code Online (Sandbox Code Playgroud)
这是我的ASIHTTPRequest代码,用于发出POST请求...
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://myrails3app.heroku.com/tournaments/%d/register.json", tid]];
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request addPostValue:username forKey:@"username"];
[request setCompletionBlock:^
{
NSData *responseData = [request responseData];
NSLog(@"Success!");
}];
// Set the code to be called when the request fails
[request setFailedBlock:^
{
NSError *error = [request error];
NSLog(@"Error: %@", [error localizedDescription]);
}];
// Start …Run Code Online (Sandbox Code Playgroud)