gpt4 book ai didi

iphone - NSURLConnection 委托(delegate)方法

转载 作者:技术小花猫 更新时间:2023-10-29 11:09:41 24 4
gpt4 key购买 nike

我很难找到 NSURLConnection 委托(delegate)方法实现的任何示例。

我想通过单击按钮通过 HTTP post 发送数据。不确定如何制作“提交”屏幕和“已提交”。 (我知道如何使用微调器并将使用它们)

我在单击按钮操作下使用此代码,但无法使用任何委托(delegate)内容。不确定如何使用我当前的设置来实现它们。

NSMutableURLRequest *request = 
[[NSMutableURLRequest alloc] initWithURL:
[NSURL URLWithString:@"http://myURL.com"]];

[request setHTTPMethod:@"POST"];

NSString *postString = [wait stringByAppendingString:co];

[request setValue:[NSString
stringWithFormat:@"%d", [postString length]]
forHTTPHeaderField:@"Content-length"];



[request setHTTPBody:[postString
dataUsingEncoding:NSUTF8StringEncoding]];

//[[NSURLConnection alloc] initWithRequest:request delegate:self];
[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];


[SVProgressHUD dismissWithSuccess:@"Submission Successful"];

最佳答案

- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Did Receive Response %@", response);
responseData = [[NSMutableData alloc]init];
}
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
{
//NSLog(@"Did Receive Data %@", data);
[responseData appendData:data];
}
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
{
NSLog(@"Did Fail");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Did Finish");
// Do something with responseData
}

关于iphone - NSURLConnection 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9577317/

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