【发布时间】:2012-02-20 19:28:53
【问题描述】:
更新:NSURLConnection 现在似乎可以正确支持 100-Continue。在任何情况下,this answer 都包含一个指向为 iOS/OSX 构建 libcurl 的脚本的链接。
我在使用 NSURLConnection 时遇到了一些困难,因为它不支持 RFC 2616 (HTTP/1.1) 的 Section 8.2.3。
基本上客户端需要能够支持发送headerExpect: 100-Continue;在发送请求标头后,它必须在发送POST/PUT 正文之前等待来自服务器的状态码为100 的响应。
此外,NSURLConnection(以及因此构建在它之上的所有库)在所有数据上传之前不会从服务器返回任何响应 - 这是一个痛苦,因为服务器可能会立即拒绝上传(无效凭据、没有空间、文件太大等)。
虽然它对小文件“工作”(内容已完全上传并调用带有响应的委托方法),但在大文件上而不是从服务器获取错误响应(我肯定已发送),我只是收到“连接失败”错误。
我知道libcurl 正确支持100-Continue 规范,所以我需要一些帮助来编译它并让它在iOS 5 项目上运行。
我从this post(滚动到底部)开始,但我走不远......
进行了这些更改...
export CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2
export CFLAGS="-arch armv7 --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"
export CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-cpp-4.2
export AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar
./configure --disable-shared --without-ssl --without-libssh2 --without-ca-bundle --without-ldap --disable-ldap --host=arm-apple-darwin10 --build=arm-apple-darwin10
make clean
make
ar rv libcurl.armv7.a lib/*.o
...但编译失败并显示消息
(...)
checking for arm-apple-darwin10-gcc... /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2
checking whether the C compiler works... no
configure: error: in `/Users/bruno/Downloads/curl-7.21.4':
configure: error: C compiler cannot create executables
我正在使用 curl 7.21.4,从 Apple 的 open source site 下载。
那么,如何编译 curl 并在 iOS 5 项目中使用它,最好支持 SSL?
【问题讨论】:
-
获取最新最好的脚本here。使用 Darwin SSL 编译——没错,原生 iOS/OSX SSL!
标签: ios5 nsurlconnection libcurl