[英]How to send data from iPhone to a Server and show it in the site
What I've learned and things that I'm not sure about if I need: 我学到的东西以及不确定是否需要的东西:
NSData
and NSUrl
with json . NSData
和json的NSUrl
从iPhone发送数据到服务器。 But I don't even know where to write PHP files to deploy on sites or anything about database creation. 但是我什至不知道在哪里写PHP文件以部署在网站上或有关数据库创建的任何内容。
This are some Tutorials that helps you. 这是一些可以帮助您的教程。
1 Using PHP's JSON encode and decode functions to handle data sent to and from your app 1 使用PHP的JSON编码和解码功能来处理与您的应用之间发送和发送的数据
At first start developing the web service .To start with a local server Use any webserver like XAMP,LAMP,tomcat,ect. 首先开始开发Web服务。要从本地服务器开始使用任何XAMP,LAMP,tomcat等网络服务器。
create a database using the phpMyadmin from your browser and also a user name to use by your application. 在浏览器中使用phpMyadmin创建数据库,并使用应用程序使用用户名。
Use the URL like localhost/home/../api.php to get the api which interacts to our application.it depends on the server you use and you can get it XAMP , LAMP 使用localhost / home /../ api.php之类的URL获取与我们的应用程序交互的api。它取决于您使用的服务器,您可以获取它XAMP , LAMP
Use php to code the api and for making the output in json, you can use json_encode() . 使用php编码api并在json中进行输出,可以使用json_encode() 。
in Your iOS app, use a method to post the request, such as NSMutableURLRequest with required parameters. 在您的iOS应用中,使用一种方法来发布请求,例如带有必需参数的NSMutableURLRequest 。
To make a request in json format you can use 要以json格式发出请求,您可以使用
NSString *jsonRequest = [jsonDict JSONRepresentation]; NSString * jsonRequest = [jsonDict JSONRepresentation];
This should be placed in the body of the post request. 这应该放在发布请求的正文中。 You can also use normal post
您也可以使用普通帖子
request with parameters. 带参数的要求。 I depends on how you process your request at the api.
我取决于您如何在api上处理您的请求。
To get the response from api, implement NSURLConnectionDataDelegate , 要从api获取响应,请实现NSURLConnectionDataDelegate,
NSURLConnectionDataDelegate methods. NSURLConnectionDataDelegate方法。
To get the json object from response 从响应中获取json对象
json=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]; json = [NSJSONSerialization JSONObjectWithData:responseData选项:NSJSONReadingMutableLeaves错误:&error];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.