gpt4 book ai didi

ios - 以单一方法运行两个网址

转载 作者:行者123 更新时间:2023-11-29 12:42:55 25 4
gpt4 key购买 nike

我正在寻找以一种方法运行 2 个服务的方法,一个接一个地发布图像。在第一个服务之后,我需要得到响应,然后我需要将该响应传递给第二个服务。

我用来发布运行单个服务以发布单个图像的代码是

NSString *url=[NSString stringWithFormat:@"http://37.187.152.236/UserImage.svc/InsertObjectImage?%@",requestString];
NSLog(@"url1%@",url);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];

// Create 'POST' MutableRequest with Data and Other Image Attachment.

NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage1, 0.2f);
[request addValue:@"image/JPEG" forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[NSData dataWithData:data]];
[request setHTTPBody:body];

stackoverflow 中可能有一些类似的问题,但我的需求完全不同。

方法流程一定是这样的 *运行第一个 url --> 生成响应 ({userid:"20",message:"success"} ) --> 运行第二个 url *

帮帮我,先谢谢大家了。

最佳答案

可以根据第一个方法的响应调用第二个方法

-(void)webservicecall {
WebApiController *obj=[[WebApiController alloc]init];

NSMutableDictionary *imageparameter = [NSMutableDictionary dictionary];

NSData *imagedata = UIImagePNGRepresentation(self.productImageView.image);

[imageparameter setValue:imagedata forKey:@"image"];

[obj callAPIWithImage:@"upload.php" WithImageParameter:imageparameter WithoutImageParameter:nil SuccessCallback:@selector(upload_response:Response:) andDelegate:self];

}

来自 Web 服务的响应:

-(void)upload_response:(NSString *)apiAlias Response:(NSData *)response {

NSMutableDictionary *jsonDictionary=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];

NSString *responseMsg=[[NSString alloc] initWithString:[jsonDictionary objectForKey:@"message"]];

if ([responseCode isEqualToString:@"success"]) {
[self CallToSecondWebService];

}

}

第二个网络服务:

-(void)CallToSecondWebService
{

}

关于ios - 以单一方法运行两个网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24443975/

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