我有一个EMR应用程序,我希望我可以将我收集的数据像图像和语音发送到服务器。在数据库中,我该如何做到这一点。有没有办法通过post方法将这些数据发送到服务器。如何将数据从iphone应用程序上传到mysql数据库
0
A
回答
1
这里是一个HTTP POST请求的例子
// define your form fields here:
NSString *content = @"field1=42&field2=Hello";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.example.com/form.php"]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[content dataUsingEncoding:NSISOLatin1StringEncoding]];
// generates an autoreleased NSURLConnection
[NSURLConnection connectionWithRequest:request delegate:self];
本教程也很有帮助http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service
0
在这种情况下,你可以做遵循两种方式: 1.如果您严格使用POST(我喜欢),您可以使用cocoahttpserver项目:
https://github.com/robbiehanson/CocoaHTTPServer
在iPhone应用程序,你可以做到这一点的代码来发送POST请求:
-(NSDictionary *) getJSONAnswerForFunctionVersionTwo:(NSString *)function
withJSONRequest:(NSMutableDictionary *)request;
{
[self updateUIwithMessage:@"server download is started" withObjectID:nil withLatestMessage:NO error:NO];
NSDictionary *finalResultAlloc = [[NSMutableDictionary alloc] init];
@autoreleasepool {
NSError *error = nil;
NSString *jsonStringForReturn = [request JSONStringWithOptions:JKSerializeOptionNone serializeUnsupportedClassesUsingBlock:nil error:&error];
if (error) NSLog(@"CLIENT CONTROLLER: json decoding error:%@ in function:%@",[error localizedDescription],function);
NSData *bodyData = [jsonStringForReturn dataUsingEncoding:NSUTF8StringEncoding];
NSData *dataForBody = [[[NSData alloc] initWithData:bodyData] autorelease];
//NSLog(@"CLIENT CONTROLLER: string lenght is:%@ bytes",[NSNumber numberWithUnsignedInteger:[dataForBody length]]);
NSString *functionString = [NSString stringWithFormat:@"/%@",function];
NSURL *urlForRequest = [NSURL URLWithString:functionString relativeToURL:mainServer];
NSMutableURLRequest *requestToServer = [NSMutableURLRequest requestWithURL:urlForRequest];
[requestToServer setHTTPMethod:@"POST"];
[requestToServer setHTTPBody:dataForBody];
[requestToServer setTimeoutInterval:600];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[urlForRequest host]];
NSData *receivedResult = [NSURLConnection sendSynchronousRequest:requestToServer returningResponse:nil error:&error];
if (error) {
NSLog(@"CLIENT CONTROLLER: getJSON answer error download:%@",[error localizedDescription]);
[self updateUIwithMessage:[error localizedDescription] withObjectID:nil withLatestMessage:YES error:NO];
[finalResultAlloc release];
return nil;
}
NSString *answer = [[NSString alloc] initWithData:receivedResult encoding:NSUTF8StringEncoding];
JSONDecoder *jkitDecoder = [JSONDecoder decoder];
NSDictionary *finalResult = [jkitDecoder objectWithUTF8String:(const unsigned char *)[answer UTF8String] length:[answer length] error:&error];
[finalResultAlloc setValuesForKeysWithDictionary:finalResult];
[answer release];
[self updateUIwithMessage:@"server download is finished" withObjectID:nil withLatestMessage:NO error:NO];
if (error) NSLog(@"CLIENT CONTROLLER: getJSON answer failed to decode answer with error:%@",[error localizedDescription]);
}
NSDictionary *finalResultToReturn = [NSDictionary dictionaryWithDictionary:finalResultAlloc];
[finalResultAlloc release];
return finalResultToReturn;
}
千万别忘了带上与图像为base64属性。
最后,如果你不喜欢保存数据,你发送给你的Mac应用程序,你可以使用任何数据库C api发送到你的数据库。我建议使用核心数据来保存接收数据。
相关问题
- 1. 如何从iPhone应用程序访问远程MySql数据库
- 2. iPhone应用程序从Mysql数据库获取数据
- 3. iPhone应用程序数据库:MySQL&SQLite
- 4. 如何从iPhone应用程序连接到远程数据库?
- 5. 应用程序如何将数据上传到在线数据库
- 6. 如何从Android应用程序中将数据插入到MySQL数据库中?
- 7. 将iphone应用程序连接到mysql数据库
- 8. 如何将图像上传到mysql数据库iOS应用程序
- 9. 将文件从iPhone/iPad上传到mysql数据库?
- 10. 将数据从iPhone应用程序传递到PHP文件
- 11. 如何将数据从mysql数据库传递到$ _SESSOIN
- 12. 从Android应用程序发送数据到MySQL数据库
- 13. 从android应用程序插入数据到mySql数据库
- 14. 从Android应用程序提交数据到MySQL数据库
- 15. 从Android应用程序传输数据到外部数据库
- 16. 如何从远程MySQL数据库获取数据到您的应用程序?
- 17. 如何使用phpMyAdmin将数据从zip文件上传到MySQL数据库?
- 18. 如何在线上传数据库并从该数据库接收数据到android应用程序?
- 19. 如何将MySQL数据库连接到C#WinForm应用程序?
- 20. 如何将Android应用程序连接到MySql数据库
- 21. 如何从Android应用程序连接到MySQL数据库
- 22. 通过PHP将数据从MySQL传递到C#应用程序
- 23. 从iOS应用程序将图像存储到MYSQL数据库
- 24. 从.net应用程序上传文件到SQL数据库
- 25. 如何从iPhone上的MAMP MySQL数据库检索数据?
- 26. iPhone应用程序从Sqlite3数据库读取数据
- 27. 如何将mysql数据上传到Elasticsearch
- 28. 如何将数据从网页传递到应用程序?
- 29. 通过webservice将JSON数据从Android应用程序传输到数据库
- 30. 如何备份应用程序数据库以将其恢复到iPhone上
你可以使用ASIHTTPRequest – welsonla 2012-03-13 06:09:22
你能告诉我样本或代码的帮助吗 – user1263350 2012-03-13 06:10:54
也许这将帮助你http://stackoverflow.com/questions/7792949/ios-5-https-asihttprequest-stop-working – 2012-03-13 06:24:04