将 NSMutable 数组发送到 iOS 中的 php 脚本 [英] Sending an NSMutable Array to a php script in iOS
问题描述
我正在制作一个 iPhone 应用程序,它需要将几个数组发送到 php 脚本,然后 php 脚本需要获取这些数组的值并编写一个 xml 文件.我知道如何用 php 编写 xml 文件,但我不确定如何将数据从 iOS 应用程序发送到 php 脚本...
是否可以从 iOS 向 php 脚本发送几个整数参数?抱歉,我对 php 和 iOS 很陌生(一般来说就是编程).
谢谢
从 iOS 应用发出 GET 或 POST 请求
示例:
NSURL *url = [NSURL URLWithString:@"http://www.site.com/sendData.php"];NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:urlcachePolicy:NSURLRequestReloadIgnoringCacheData超时间隔:60];[theRequest setHTTPMethod:@"POST"];[theRequest setValue:@"application/x-www-form-urlencoded" for HTTPHeaderField:@"Content-Type"];NSString *postData = [NSString stringWithFormat:@"name1=%@&name2=%@", data1, data2];NSString *length = [NSString stringWithFormat:@"%d", [postData length]];[theRequest setValue:length forHTTPHeaderField:@"Content-Length"];[theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest 委托:self];[s连接开始];
<块引用>
为了下载 URL 的内容,应用程序需要提供至少实现以下内容的委托对象委托方法:connection:didReceiveResponse:,connection:didReceiveData:, connection:didFailWithError: 和connectionDidFinishLoading:.
关于 NSURLConnection关于 NSURLRequest
I am making an iPhone app which needs to send a couple of arrays to a php script and then the php script needs to take the value(s) of those arrays and write an xml file. I know how to write the xml file with php, but I am unsure how to send the data to the php script from the iOS app...
Is it even possible to send a php script a couple of integer arguments from iOS? Sorry I am very new to php and iOS (programming in general for that matter).
Thanks
make GET or POST request from iOS app
example:
NSURL *url = [NSURL URLWithString:@"http://www.site.com/sendData.php"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSString *postData = [NSString stringWithFormat:@"name1=%@&name2=%@", data1, data2];
NSString *length = [NSString stringWithFormat:@"%d", [postData length]];
[theRequest setValue:length forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];
NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];
[sConnection start];
In order to download the contents of a URL, an application needs to provide a delegate object that, at a minimum, implements the following delegate methods: connection:didReceiveResponse:, connection:didReceiveData:, connection:didFailWithError: and connectionDidFinishLoading:.
about NSURLConnection about NSURLRequest
这篇关于将 NSMutable 数组发送到 iOS 中的 php 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!