如何发送数据从iphone到服务器使用url
问题描述:
我想知道如何我可以从我的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