ios post html,iOS post表单提交 报http 500错误详解
完整代码:NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",[utils getAppUploadMeidaUrl],UploadPIC] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];ASIFormDataRequest .
完整代码:
NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",[utils getAppUploadMeidaUrl],UploadPIC] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *dictonary = [ASIFormDataRequest requestWithURL:url];
[dictonarysetRequestMethod:@"POST"];
//改用这个方法设置header
NSMutableDictionary *header = [[NSMutableDictionary alloc] init];
[headersetValue:@"multipart/form-data" forKey:@"Content-Type"];
[dictonarysetRequestHeaders:header];
[dictonary setPostValue:[utils getUnitID] forKey:@"unitId"];
[dictonary setPostValue:model.componentsTypeName forKey:@"objName"];//部件名称
[dictonary setPostValue:model.componentsCategory forKey:@"componentsCategory"];//部件大类
[dictonary setPostValue:model.componentsType forKey:@"componentsType"];//部件小类
//上传图片
if(self.arrPic.count) {
for(UIImage*eImage in self.arrPic) {
intx =arc4random() %100;
inty =arc4random() %100;
NSData*imageData=UIImageJPEGRepresentation(eImage,100);
NSString*photoName=[NSStringstringWithFormat:@"%zd-%zd.jpg",x,y];
//照片content
[dictonary addData:imageData withFileName:photoName andContentType:@"image/jpeg" forKey:@"picFile"];
}
}else{
//无照片时,后台规定也必须传 picFile 字段
[dictonary addData:@"" withFileName:@"" andContentType:@"image/jpeg" forKey:@"picFile"];
}
[dictonary buildPostBody];
dictonary.shouldAttemptPersistentConnection=NO;
[dictonary setDelegate:self];
[dictonary setDidFailSelector:@selector(responseFailed)];
[dictonary setDidFinishSelector:@selector(responseComplete:)];
[dictonary setTimeOutSeconds:30];
[dictonary startSynchronous];
更多推荐
所有评论(0)