gpt4 book ai didi

ios - 如何使用相同的连接发送不同的请求?

转载 作者:行者123 更新时间:2023-11-28 17:54:53 25 4
gpt4 key购买 nike

我的应用行为如下:

Client: sent a request (using a NSURLConnection) to server asking server to generate a file and download that file.

Server: generate the file and send the file's data back to client (using chunked encoding)

After generating the file, server will update the file's header, so after downloading file, client needs to make second request to get the updated header. During file generating and updating, if server detects that connection from client is closed, it will delete the generated file, so the connection need to be kept alive.

Client: sent a second request (another NSURLConnection) to get updated header

问题是在第一次请求后(我使用 NSURLConnection)服务器检测到连接关闭并删除生成的文件,所以第二次请求失败。

我怀疑原因是我使用了两个不同的 NSURLConnection 实例,所以我在文档中查找类似 NSMutableURLConnection 的内容。它不存在!

我的问题:有没有办法在请求之间保持连接(通过重用 NSURLConnection,或使用 NSMutableRequest 并使用相同的 NSURLConnection 重新请求)?

最佳答案

你可以使用:

NSURLConnection *currentConnection = [NSURLConnection alloc]; 
[currentConnection initWithRequest:request1 delegate:self];

[currentConnection initWithRequest:request2 delegate:self];

您可以使用以下方法验证原始和当前 NSURLRequest:

- (NSURLRequest *)originalRequest NS_AVAILABLE_IOS(5_0);
- (NSURLRequest *)currentRequest NS_AVAILABLE_IOS(5_0);

关于ios - 如何使用相同的连接发送不同的请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14392572/

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