ASIHTTP请求中的问题

时间:2012-08-31 08:15:08

标签: php ios xcode web-services asihttprequest

我使用ASIHTTP将json数据和一个图像发送到服务器。代码是

- (IBAction)performLargeUpload1:(id)sender
{
    [request cancel];

    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"James", @"Name", @"/imagepath/", @"image",nil];
    NSString *jsonString = [dict JSONRepresentation];

    NSLog(@"jsonString : %@", jsonString);

    [self setRequest:[ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"My Url"]]];

    [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"]; 
    [request addRequestHeader:@"Content-Type" value:@"application/json"];
    [request appendPostData:[jsonString  dataUsingEncoding:NSUTF8StringEncoding]];
    [request setTimeOutSeconds:20];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
    [request setShouldContinueWhenAppEntersBackground:YES];
#endif
    [request setUploadProgressDelegate:progressIndicator];
    [request setDelegate:self];
    [request setDidFailSelector:@selector(uploadFailed:)];
    [request setDidFinishSelector:@selector(uploadFinished:)];

    UIImage *image;
    image = [UIImage imageNamed:@"testImg1.jpg"];
    ////NSLog(@"cur img i s:%@",image);
    NSData *data = UIImageJPEGRepresentation(image, 0.9f);

    NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"file"];
    [data writeToFile:path atomically:NO];

    //Add the file 2 times to the request, 
    for (i=0; i<2; i++) {
        [request setFile:path forKey:[NSString stringWithFormat:@"file-%i",i]];
    }

    [request startAsynchronous];
    [resultView setText:@"Uploading data..."];
}

成功上传到服务器。但我无法在服务器端检索数据。任何人都可以建议我在PHP中的代码来检索数据吗?

0 个答案:

没有答案