使用 Objective-C 在 iPhone 上使用 HTTP POST 和 GET 的教程 [英] Tutorials for using HTTP POST and GET on the iPhone in Objective-C
本文介绍了使用 Objective-C 在 iPhone 上使用 HTTP POST 和 GET 的教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下载了苹果的使用 HTTP POST 和 GET 的演示(他们的示例应用程序有一个包含不同部分的标签栏),代码很混乱!
I downloaded apple's demo for using HTTP POST and GET (Their sample app has a tabbar with different parts) and the code is so confusing!
谁能给我一些示例代码或有关它的一些教程的链接?:)
Could anybody give me some sample code or a link to some tutorials about it? :)
谢谢!
推荐答案
Matt Long 的这个演练特别好:http://www.cimgf.com/2010/02/12/accessing-the-cloud-from-cocoa-touch/
This walkthrough by Matt Long is particularly good: http://www.cimgf.com/2010/02/12/accessing-the-cloud-from-cocoa-touch/
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL
URLWithString:@"http://www.cimgf.com/testpost.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/xml"
forHTTPHeaderField:@"Content-type"];
NSString *xmlString = @"<data><item>Item 1</item><item>Item 2</item></data>";
[request setValue:[NSString stringWithFormat:@"%d",
[xmlString length]]
forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[xmlString
dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc]
initWithRequest:request
delegate:self];
这篇关于使用 Objective-C 在 iPhone 上使用 HTTP POST 和 GET 的教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文