【发布时间】:2011-09-07 11:01:04
【问题描述】:
我正在尝试将数据从 iPhone 同步到服务器,但没有得到它。在过去的四天里,我曾经这样做过,但现在没有任何成功。它显示
- ** 连接失败!错误 - 请求超时。 http://192.168.0.68:91/JMAPI?RequestType=User&Command=NEW
- ** -[NSConcreteMutableData release]:消息发送到 deallocated 实例 0x165590a0
我的服务器是在 C# 的帮助下创建的 我有这样的本地服务器链接http://192.168.0.68:91/JMAPI 为了发布我这样编码的数据
-(void)sendRequest
{
NSDate* date = [NSDate date];
//Create the dateformatter object
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
//Set the required date format
[formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
//Get the string date
NSString* str = [formatter stringFromDate:date];
NSString *post = [NSString stringWithFormat:@"Token=%@&JourneyID=%@&JourneyName=%@&Locationname=%@&StartDate=%@&Distance=%@&ShareType=%@&LastSyncDate=%@",tokenapi,Journey_ID,Journey_Name,Location_Name,Start_Date,Dist,Share_type,str];
NSLog(@"%@",post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"%@",postLength);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init]autorelease];
[request setURL:[NSURL URLWithString:@"http://192.168.0.68:91/JMAPI?RequestType=User&Command=NEW"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
webData = [[NSMutableData data] retain];
NSLog(@"%@",webData);
}
}
/// this for checking is that Sync is work or not
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[webData release];
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
***//ABove line i am getting error that Connection failed! Error - The request timed out.
http://192.168.0.68:91/JMAPI?RequestType=User&Command=NEW***
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",loginStatus);
[loginStatus release];
[connection release];
[webData release];
}
And i am getting this data from sqlitedatabase and from here i am calling the -(void)sendRequest Which is containing posting method . For code like this
-(void)information
{
NSString *filePath = [self getWritableDBPath];
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK)
{
NSString *qu = @"Select JourneyID,JourneyName,Locationname,StartDate,Distance,ShareType FROM UserJourney where SyncStatus ='1'";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [qu UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
{
while(sqlite3_step(compiledStatement) == SQLITE_ROW )
{
char *firstColumn = (char *)sqlite3_column_text(compiledStatement, 0);
Journey_ID= [[NSString alloc]initWithUTF8String:firstColumn];
NSLog(@"%@",Journey_ID);
char * scondColumn = (char *)sqlite3_column_text(compiledStatement, 1);
Journey_Name = [[NSString alloc]initWithUTF8String:scondColumn];
NSLog(@"%@",Journey_Name);
char *thridColumn = (char *)sqlite3_column_text(compiledStatement, 2);
Location_Name =[[NSString alloc]initWithUTF8String:thridColumn];
NSLog(@"%@",Location_Name);
char *fuothColumn = (char *)sqlite3_column_text(compiledStatement, 3);
Start_Date = [[NSString alloc]initWithUTF8String:fuothColumn];
NSLog(@"%@",Start_Date);
Dist = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 4)];
NSLog(@"%f",Dist);
Share_type = [NSNumber numberWithInt:(int)sqlite3_column_int(compiledStatement, 5)];
NSLog(@"%f",Share_type);
NSLog(@"%@,%@,%@,%@,%@",Journey_ID,Journey_Name,Location_Name,Start_Date,Dist,Share_type);
[self sendRequest];***// this is place from where I call the posting method(sendRequest)***
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
希望尽快得到帮助 谢谢
【问题讨论】:
-
打开 NSZombie 并通过 Instruments 进行测试。它将帮助您找到双重释放的对象。
-
从浏览器检查 URL 192.168.0.68:91/JMAPI?RequestType=User&Command=NEW 是否正常工作或超时。
标签: iphone objective-c