我有一個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. 應用程序如何將數據上傳到在線數據庫
- 3. 如何從iPhone應用程序連接到遠程數據庫?
- 4. 將iphone應用程序連接到mysql數據庫
- 5. 從Android應用程序提交數據到MySQL數據庫
- 6. 從android應用程序插入數據到mySql數據庫
- 7. 從Android應用程序傳輸數據到外部數據庫
- 8. 如何使用phpMyAdmin將數據從zip文件上傳到MySQL數據庫?
- 9. 如何將MySQL數據庫連接到C#WinForm應用程序?
- 10. 如何將Android應用程序連接到MySql數據庫
- 11. 如何從Android應用程序連接到MySQL數據庫
- 12. 將文件上傳到MYSQL數據庫
- 13. 如何將mysql數據上傳到Elasticsearch
- 14. 如何將數據從網頁傳遞到應用程序?
- 15. 通過webservice將JSON數據從Android應用程序傳輸到數據庫
- 16. 格式從MySQL數據庫爲iPhone應用程序
- 17. 如何將XML數據從Java應用程序傳輸到.net應用程序
- 18. 上傳數據到遠程數據庫
- 19. 如何使用ajax將圖像上傳到MySql數據庫......?
- 20. 如何使用PHP將Excel或CSV上傳到MySQL數據庫?
- 21. 如何將數據從Azure數據庫表獲取到Android應用程序?
- 22. 如何使用java將數據上傳到數據庫?
- 23. 如何更新我的iPhone應用程序上的數據庫?
- 24. 從Android應用程序上傳數據到桌面程序
- 25. 如何從iPhone應用程序訪問Xcode數據庫
- 26. Android ..如何將數據從android手機上傳到遠程數據庫?
- 27. 如何將數據從MYsql服務器傳輸到iphone
- 28. 將SQL數據庫從Azure Blob Azure上傳到SQL數據庫
- 29. 使用java將數據從excel文件上傳到數據庫
- 30. Android:將文本文件數據上傳到MySQL數據庫
你可以使用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