![](/img/trans.png)
[英]iOS AFNetworking internal server error (500) when uploading an image by post
[英]500 Internal Server Error on uploading the image
我在将图像上传到服务器时遇到问题。 并得到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
数据,这样做是为了得到响应以下string
<!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>
可能是什么问题?
这个:
[request setRequestMethod:@"PUT"];
应该:
[request setRequestMethod:@"POST"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.