1
我正在面臨將圖像上傳到服務器的問題。並獲得500 Internal Server Error
。500上傳圖像時出現內部服務器錯誤
我被下面的代碼上傳圖像
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個數據如上並通過這樣做我得到以下字符串響應
<!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>
什麼可以是問題呢?