objective-c - 在 Objective-C 中在 iPhone 上使用 HTTP POST 和 GET 的教程

标签 objective-c http post get

我下载了苹果的使用 HTTP POST 和 GET 的演示(他们的示例应用程序有一个带有不同部分的标签栏),代码太困惑了!

谁能给我一些示例代码或一些关于它的教程的链接? :)

谢谢!

最佳答案

Matt Long 的这个演练特别好: 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 - 在 Objective-C 中在 iPhone 上使用 HTTP POST 和 GET 的教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2346893/

相关文章:

objective-c - 使用Core Graphics在Objective-C(IOS)中绘制角度/角度/"Conical"/"Arcing"渐变

C# HTTP 在获取正文之前发布和只读响应的 header

html - RESTful URL 中的输出格式是如何编码的?

python - 如何在 Python 中发送和接收 HTTP POST 请求

ios - 如何清理此Objective C cornerRadius代码?

objective-c - "config.h"由 libxml 使用但未与 libxml 捆绑

ruby-on-rails - link_to : undefined local variable or method 'post' ?

Python POST 请求 - 设置整个原始帖子正文?

objective-c - 当我执行 popViewController 动画时无法显示导航栏

php - Delphi 代码在控制台中有效,但在 VLC 中无效