简体   繁体   English

上载映像时出现500 Internal Server Error

[英]500 Internal Server Error on uploading the image

I'm facing an issue to uploading an image to server. 我在将图像上传到服务器时遇到问题。 and getting 500 Internal Server Error . 并得到500 Internal Server Error

I'm uploading the image by below code 我通过以下代码上传图片

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];

and in response 并作为回应

-(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);
}

firstly there is an error on converting data JSON data to NSdictionary , and it through below 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.}

then I tried to check be converting Response data in nsstring as done above and by doing so I'm getting below string in response 然后我试图检查是否像上面那样在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>

what can be the issue? 可能是什么问题?

This: 这个:

[request setRequestMethod:@"PUT"];

Should be: 应该:

[request setRequestMethod:@"POST"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过帖子上传图像时,iOS AFNetworking内部服务器错误(500) - iOS AFNetworking internal server error (500) when uploading an image by post 图片上传内部服务器错误500仅适用于iPhone - Image upload internal server error 500 only for iphone 内部服务器错误 500 上传图片 iOS php - Internal Server Error 500 upload image iOS php AFNetworking 3.0错误:“请求失败:内部服务器错误(500)” - AFNetworking 3.0 Error: “Request failed: internal server error (500)” 使用MKNetworking图像上传PHP获取内部错误500 - Getting Internal Error 500 using MKNetworking Image Upload PHP 使用AFNetworking的iOS POST:NSLocalizedDescription =请求失败:内部服务器错误(500) - iOS POST with AFNetworking : NSLocalizedDescription=Request failed: internal server error (500) 代码= -1011“请求失败:内部服务器错误(500) - Code=-1011 "Request failed: internal server error (500) 在 HTTP 500 内部服务器错误的情况下,将调用 NSURLConnectionDataDelegate 的哪种方法? - Which method of NSURLConnectionDataDelegate will be summoned in case of HTTP 500 Internal server error? WKWebview POST 授权 Header 返回 500 内部服务器错误 - WKWebview POST with Authorization Header return 500 Internal server error 将图像上传到服务器时出错 - Getting error while uploading image into server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM