2011-04-22 48 views

回答

0

喜朋友 爲此,你需要首先使用ASIHttp連接代表以這種方式服務器交互的

0

最常見的裝置設定的連接是經由NSStringstringWithContentsOfURL:encoding:error:方法(以及其它相關方法中的NSString)和NSURLConnection類,它能夠執行異步後臺請求。

上述兩個鏈接的類參考文檔都包含代碼示例(請參閱每個頂部的「相關示例代碼」部分)。

此外,還有第三方解決方案可用,如常用的ASIHTTPRequest類。

一旦數據「命中」服務器,您就會在超級全局數據從$_GET中檢索數據,然後將其存儲在數據庫表中。對此有各種各樣的方法(使用抽象層,如PDO等),因此它取決於您的個人偏好。

0

您可以使用下面的代碼 首先,你可能有進口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]; 
0

簡單 嘗試以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. 
相關問題