gpt4 book ai didi

php - 将 NSMutable 数组发送到 iOS 中的 php 脚本

转载 作者:数据小太阳 更新时间:2023-10-29 02:46:14 26 4
gpt4 key购买 nike

我正在制作一个 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: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

关于php - 将 NSMutable 数组发送到 iOS 中的 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9022108/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com