如何将数据从 iOS 应用程序发送到 http 服务器 [英] How to send data from iOS app to http server

查看:37
本文介绍了如何将数据从 iOS 应用程序发送到 http 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 iOS 应用程序中的字符串中的一些数据发送到我的服务器,在那里 PHP 脚本会将这些数据写入数据库?

How can I send some data from a string in a iOS app to my server, where a PHP script will write this data to a database?

推荐答案

最后,我有一个代码,它有效!

so finaly, I have one code, which works!

NSString *content = @"field1=42&field2=Hello";

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.example.com/form.php"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[content dataUsingEncoding:NSUTF8StringEncoding]];

// generates an autoreleased NSURLConnection
[NSURLConnection connectionWithRequest:request delegate:self];

这篇关于如何将数据从 iOS 应用程序发送到 http 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆