2011-04-22 102 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. 
相关问题