我想知道如何我可以從我的iphone應用程序發送數據到MySQL服務器使用該網址的表。如何發送數據從iphone到服務器使用url
http://localhost/location.php?id=&[email protected]&[email protected]
其中 「@」 是從Xcode中緯度和經度變量。
我想知道如何我可以從我的iphone應用程序發送數據到MySQL服務器使用該網址的表。如何發送數據從iphone到服務器使用url
http://localhost/location.php?id=&[email protected]&[email protected]
其中 「@」 是從Xcode中緯度和經度變量。
喜朋友 爲此,你需要首先使用ASIHttp連接代表以這種方式服務器交互的
最常見的裝置設定的連接是經由NSStringstringWithContentsOfURL:encoding:error:
方法(以及其它相關方法中的NSString)和NSURLConnection類,它能夠執行異步後臺請求。
上述兩個鏈接的類參考文檔都包含代碼示例(請參閱每個頂部的「相關示例代碼」部分)。
此外,還有第三方解決方案可用,如常用的ASIHTTPRequest類。
一旦數據「命中」服務器,您就會在超級全局數據從$_GET中檢索數據,然後將其存儲在數據庫表中。對此有各種各樣的方法(使用抽象層,如PDO等),因此它取決於您的個人偏好。
您可以使用下面的代碼 首先,你可能有進口asihttprequest包和所有必需的frameworks.after是
#import "ASIHTTPRequest.h"
#import "ASINetworkQueue.h"
在你viewcontroller.h文件
ASINetworkQueue *networkQueue;
在你的viewController。 M檔: - 在viewDidLoad中: -
networkQueue=[[ASINetworkQueue queue]retain];
要發送請求寫下面的代碼: -
NSString *str = [NSString stringWithFormat:@"http://localhost/location.php?id=&latitude=%@&longitude=%@",latitude,longitude];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setRequestMethod:@"GET"];
[request setDelegate:self];
[request setDidFinishSelector: @selector(*writemethodforsuccessfulrequest*)];
[request setDidFailSelector: @selector(*writemethodforrequestfailed*)];
[networkQueue addOperation: request];
[networkQueue go];
在的dealloc: -
[networkQueue cancelAllOperations];
[networkQueue release];
簡單 嘗試以HTTP的這個
NSString *urlString = [NSString stringWithFormat:@"http://localhost/location.php?id=&latitude=%@&longitude=%@",yourLat,yourLong];
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData *returnData = [NSData dataWithContentsOfURL:url];
// returnData will be the response you get when you pass the URL. If you like to
// get some acknowledgement pass a xml format with some parameters to check
// whether the URL you sent is valid one.
重複://計算器.COM /問題/ 1571336 /搬出後數據從-iphone-過SSL-HTTPS – 2011-04-22 11:39:25