正在从目标C传递self.request.get(“profile\u pic”)Null

2024-07-05 09:53:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道如何通过POST检查Objective-C的pass Null

在目标C中:

NSData *profile_pic_data = nil; (this does not change)
...
//Profile Pic Data
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"profile_pic\"; filename=\"profile_pic.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:profile_pic_data]];
...
NSLog(@"profile_pic_data = %@", profile_pic_data); //RETURNS (null)

在Python中:

...
user_profile_pic_data = self.request.get("profile_pic")
...
if user_profile_pic_data:
   #IT RUNS THIS CODE
else:
   #IT SHOULD RUN THIS CODE

如果我在self.request.get(“profile\u pic”)设置后打印出用户资料,它不会显示任何内容

我试过:

if user_profile_pic_data:
if user_profile_pic_data is not NONE:
if user_profile_pic_data is not NONE and != '':

似乎什么都没用

有人经历过吗


Tags: selfdatagetifrequestnotbodycontent
1条回答
网友
1楼 · 发布于 2024-07-05 09:53:18

不知道你到底想在这里完成什么,但这里:

NSData *profile_pic_data = nil;

您正在将profile_pic_data设置为nil。然后将POST数据附加到body,然后再次登录profile_pic_data。因为您从来没有将它设置为除nil之外的任何值,所以它输出为nothing

也许你想profile_pic_data真的有内容?您可以使用UIImage

NSData *profile_pic_data = UIImageJPEGRepresentation(anImage);

相关问题 更多 >