gpt4 book ai didi

ios - 如何从 iOS 应用程序使用 POST 发送 NSData?

转载 作者:可可西里 更新时间:2023-11-01 03:38:18 27 4
gpt4 key购买 nike

NSData *imageData = UIImagePNGRepresentation(image);

如何使用 POST 发送图像数据?

最佳答案

下面的代码应该有帮助

NSData *imageData = UIImagePNGRepresentation(image);

NSURL *yourURL = ...
NSMutableURLRequest *yourRequest = [NSMutableURLRequest requestWithURL:yourURL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
//Set request to post
[yourRequest setHTTPMethod:@"POST"];

//Set content type
[yourRequest setValue:@"image/png" forHTTPHeaderField:@"Content-Type"];

// Set authorization header if required
...

// set data
[yourRequest setHTTPBody:imageData];


// create connection and set delegate if needed
NSURLConnection *yourConnection = [[NSURLConnection alloc] initWithRequest:yourRequest
delegate:self
startImmediately:YES];

请注意,假设您使用的是 ARC。

关于ios - 如何从 iOS 应用程序使用 POST 发送 NSData?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10753099/

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