-1

我想与 UIImage 一起上传跟随日志字符串,

我怎样才能达到这样的目标????

我可以看到只发送图像,但我想使用此 ASIFormDataRequest,使用 POST 请求类型发送图像和文本数据。

  NSLog(@"data is here %@\n%@\n%@\n%@\n%@\n",deviceID, postID, name, message, picture);


    UIImage *image= [UIImage imageNamed:@"profile_avatar.png"];
    NSString *strURL = @"https://abc.abc.com/comments/create";

    //      ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]]; // Upload a file on disk
   // NSString *filename1=[NSString stringWithFormat:@"friendship.jpg"];
    UIImage *image1=image;
    NSData *imageData1=UIImageJPEGRepresentation(image1, 1.0);

    [request setData:imageData1 withFileName:@"filename" andContentType:@"image/png" forKey:@"avatar"];
    [request setRequestMethod:@"POST"];

    [request addRequestHeader:@"Authorization" value:[NSString stringWithFormat:@"Basic %@",[ASIHTTPRequest base64forData:[[NSString stringWithFormat:@"username123:pass123"] dataUsingEncoding:NSUTF8StringEncoding]]]];

    [request setValidatesSecureCertificate:NO];
    //[request appendPostData:body];
    [request setDelegate:self];
    [request setTimeOutSeconds:3.0];
    request.shouldAttemptPersistentConnection = NO;
    [request setDidFinishSelector:@selector(uploadRequestFinished:)];
    [request setDidFailSelector:@selector(uploadRequestFailed:)];
    [request startAsynchronous];

谢谢

4

1 回答 1

3

还有一种方法可用于发送参数

[request setPostValue:@"YourValue" forKey:@"YourKey"];
于 2013-10-24T10:40:33.993 回答