URL 中含有中文 必须编码

- (IBAction)submit:(id)sender {   

    NSString *pathh =  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];    NSString *filePathh = [pathh stringByAppendingPathComponent:@"userlogin.plist"];    self.account = [NSKeyedUnarchiver unarchiveObjectWithFile:filePathh];   

//    http://192.168.10.47:8080/user/PostSingleAddShare.html?id=10394&userId=1001640054&forward=10394&postTitle=标题!&postContent=内容!       //发送请求
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
       
        NSString *str= [NSString stringWithFormat:@"/user/PostSingleAddShare.html?id=%@&userId=%@&forward=%@&postTitle=%@&postContent=%@",self.productId,self.account.userId,self.productId,self.zbtitle.text,self.zbcontent.text];       
         NSString *all = [ZBTestURL stringByAppendingString:str];
            NSString* str2 = [all stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL *url2 = [NSURL URLWithString:str2];

          NSURLSession *session2 = [NSURLSession sharedSession];
          NSURLSessionDataTask *dataTask2 = [session2 dataTaskWithURL:url2 completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
           
            NSString *aString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
           
          
           
            dispatch_async(dispatch_get_main_queue(), ^{
               
               
               
                if ([aString isEqualToString:@"true"]) {
                   
                    [SVProgressHUD  showSuccessWithStatus:@"提交审核通过,等待审核中..."];
                    [self.navigationController popViewControllerAnimated:YES];
                }else{
                    [SVProgressHUD showErrorWithStatus:@"提交失败"];

                     }
            });
           
        }];
        [dataTask2 resume];
       
    });
   
}
 

你可能感兴趣的:(URL 中含有中文 必须编码)