gpt4 book ai didi

ios5 - 在 iOS 5 上使用 libcurl 作为 NSURLConnection 的替代品

转载 作者:行者123 更新时间:2023-12-04 01:35:25 24 4
gpt4 key购买 nike

更新:NSURLConnection 现在似乎可以正确支持 100-Continue。无论如何,this answer包含为 iOS/OSX 构建 libcurl 的脚本的链接。

我对 NSURLConnection 有点困难, 因为它不支持 Section 8.2.3 RFC 2616 (HTTP/1.1)。

基本上客户端需要能够支持发送 header Expect: 100-Continue ;发送请求头后,必须等待来自服务器的响应,状态码为 100在发送 POST 之前/PUT body 。

此外,NSURLConnection (因此所有建立在它之上的库)在上传所有数据之前不会从服务器返回任何响应 - 这是一个痛苦,因为服务器可能会立即拒绝上传(无效的凭据,没有空间,文件太大, ETC)。
虽然它对小文件“工作”(内容已完全上传并调用带有响应的委托(delegate)方法),但在大文件上而不是从服务器获取错误响应(我是 肯定会发送 ) ,我只是收到“连接失败”错误。

我知道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?

最佳答案

这对我使用最新的 SDK 有效:

#!/bin/sh 
export SDK=5.0

buildit()
{
target=$1
platform=$2

export CC=/Developer/Platforms/${platform}.platform/Developer/usr/bin/gcc
export CFLAGS="-arch ${target} -isysroot /Developer/Platforms/${platform}.platform/Developer/SDKs/${platform}${SDK}.sdk"
export CPP="/Developer/Platforms/${platform}.platform/Developer/usr/bin/llvm-cpp-4.2"
export AR=/Developer/Platforms/${platform}.platform/Developer/usr/bin/ar
export RANLIB=/Developer/Platforms/${platform}.platform/Developer/usr/bin/ranlib

./configure --disable-shared --without-ssl --without-libssh2 --without-ca-bundle --without-ldap --disable-ldap \
--host=${target}-apple-darwin10

make clean
make
$AR rv libcurl.${target}.a lib/*.o
}

buildit armv6 iPhoneOS
buildit armv7 iPhoneOS
buildit i386 iPhoneSimulator

lipo -create libcurl.armv7.a libcurl.armv6.a libcurl.i386.a -output libcurl.a

关于ios5 - 在 iOS 5 上使用 libcurl 作为 NSURLConnection 的替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9039554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com