将数据从 iPhone 发送到 Web 服务 [英] Send data from an iPhone to a Web service
问题描述
我正在开发一个 iPad 应用程序,用户在其中填写他们的详细信息并按下提交按钮,该按钮将信息发送到特定的 Web 服务器(稍后将被一个人查看)
I'm developing an iPad application in which a user fills in their details and presses a submit button, which sends the information to a specific Web server (which will later be viewed by a person)
就 Web 服务协议而言,我知道 JSON 和 XML.是否还有其他协议需要我研究?(或者可能是完全不同的方法)
As far as protocols for Web services are concerned, I know JSON and XML. Are there any other protocols that I should be looking into? (or perhaps by a different method completely)
如果能得到任何帮助,我将不胜感激.
I'd be very grateful for any help.
推荐答案
如果你只是想向服务器发送文本信息,你可以试试这个代码:
If you just want to send text info to server you can try this code:
NSString *textdata = [YourTextField text];
NSString *anotherTextdata = [YourAnotherTextField text];
NSString *urlpath;
urlpath = [@"http://yoursiteapiurl.com/" stringByAppendingString:@"yourserverfile.php?textdata="];
urlpath = [urlpath stringByAppendingString:textdata];
urlpath = [urlpath stringByAppendingString:@"&anotherTextData="];
urlpath = [urlpath stringByAppendingString:anotherTextdata];
NSURL *url=[[NSURL alloc] initWithString:[urlpath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *a = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
变量 a
将具有此 URL 的响应.服务器可以发送 XML,然后您可以使用任何 XML 解析技术解析该 XML.
The variable a
will have the response of this URL. The server could send XML and then you can parse that XML using any XML parsing technique.
这篇关于将数据从 iPhone 发送到 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!