Ios 为什么web浏览器中的url未加载到UIImageview中

Ios 为什么web浏览器中的url未加载到UIImageview中,ios,objective-c,uiimageview,Ios,Objective C,Uiimageview,我的应用程序中的Hi希望显示url中的图像。url基于此处的api响应,共享一个示例格式 当我在web浏览器中浏览此响应时,会显示图像,但当我尝试将其加载到UIImageView中时,不会显示图像。当我从:myimage中删除“:”时,它也在UIImageView中工作。为什么web浏览器中的url未加载到UIImageview中 下面是我的代码 NSString *STR_url = @"https://myserver.com/:myimage.jpg"; _IMG_imageVW.

我的应用程序中的Hi希望显示url中的图像。url基于此处的api响应,共享一个示例格式 当我在web浏览器中浏览此响应时,会显示图像,但当我尝试将其加载到UIImageView中时,不会显示图像。当我从:myimage中删除“:”时,它也在UIImageView中工作。为什么web浏览器中的url未加载到UIImageview中

下面是我的代码

NSString *STR_url = @"https://myserver.com/:myimage.jpg";
    _IMG_imageVW.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:STR_url]]];
工作代码是

NSString *STR_api = @"https://myserver.com/";
    NSString *STR_image_resp = @":myimage.jpg";
    STR_image_resp = [STR_image_resp stringByReplacingOccurrencesOfString:@":" withString:@""];
    NSString *STR_final = [NSString stringWithFormat:@"%@%@",STR_api,STR_image_resp];
_IMG_imageVW.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:STR_final]]];

您可以使用以下代码来解决您的问题。 这里是可以找到SDWebImageView类文件的链接。


如果要使用URLWithString初始化,则应正确编码参数。例如,如果要加载文件名中带有空格的联机图像文件,则应使用%20对其进行转换。它在浏览器中加载,因为浏览器将执行转换

你可以在下面试试看- NSString*URLESCESCAPEDSTRING=
[STR_url StringByAddingPercentEncoding with AllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]

您是否在应用程序中添加了传输安全性?您的意思是NSAppTransportSecurity NSAllowsArbilarLoads@Anbu.Karthikyes,dataWithContentsOfURL在主线程中工作,因此您需要等待延迟。您是否可以打印此STR_final?回答是问题中的STR_url
 NSString* UserImage=[NSString stringWithFormat:@"%@",[[UserFeedArray objectAtIndex:indexPath.row] valueForKey:@"profile"]];
      UserImage = [UserImage stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
     [cell.UserProfilePic sd_setImageWithURL:[NSURL URLWithString:UserImage] placeholderImage:[UIImage imageNamed:@"logo"] options:SDWebImageRefreshCached];