【问题标题】:500 Internal Server Error on uploading the image上传图片时出现 500 内部服务器错误
【发布时间】:2013-07-06 17:30:26
【问题描述】:

我在将图像上传到服务器时遇到问题。并获得500 Internal Server Error

我正在通过以下代码上传图片

ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
    [request setRequestMethod:@"PUT"];
    [request setPostValue:[[NSUserDefaults standardUserDefaults]valueForKey:@"nickname"] forKey:@"nick"];

    NSData *imageData = UIImagePNGRepresentation(img.image);
     [request addData:imageData withFileName:@"image.png" andContentType:@"image/png" forKey:@"image"];
    //[request setData:imageData withFileName:@"profileImage.jpeg" andContentType:@"image/jpeg" forKey:@"image"];

    [request setDelegate:self];
    [request setDidFinishSelector:@selector(requestSuccess:)];
    [request setDidFailSelector:@selector(requestFailed:)];
    [request startAsynchronous];

作为回应

-(void)requestSuccess:(ASIFormDataRequest *)request{
    NSLog(@"%@",[request responseData]);
    NSError *error;

    NSString* newStr = [[[NSString alloc] initWithData:[request responseData]
                                          encoding:NSUTF8StringEncoding] autorelease];
    NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:[request responseData] options:NSJSONReadingAllowFragments error:&error];

    NSLog(@"%@",error);
}

首先将数据JSON数据转换为NSdictionary时出错,并通过以下错误

 Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x8563f70 {NSDebugDescription=Invalid value around character 0.}

然后我尝试检查是否在 nsstring 中转换 Response 数据,如上所述,这样做我得到低于字符串的响应

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
 <title>500 Internal Server Error</title>
 <h1>Internal Server Error</h1>
 <p>The server encountered an internal error and was unable to complete your request.    Either the server is overloaded or there is an error in the application.</p>

可能是什么问题?

【问题讨论】:

    标签: objective-c ios6 uiimage


    【解决方案1】:

    这个:

    [request setRequestMethod:@"PUT"];
    

    应该是:

    [request setRequestMethod:@"POST"];
    

    【讨论】:

      猜你喜欢
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      • 2014-01-04
      • 2014-04-12
      相关资源
      最近更新 更多