这就是我实施的内容
.h部分
#import <UIKit/UIKit.h> #import "GlobalAccessClass.h" #import <QuartzCore/QuartzCore.h> @interface AskQuestionHome : UIVIEwController<UITextVIEwDelegate,UITextFIEldDelegate,UIImagePickerControllerDelegate,UIActionSheetDelegate> { } @property (strong,nonatomic) IBOutlet UIImageVIEw *imgSecondimg; @property (strong,nonatomic) IBOutlet UIImageVIEw *imgFirstimg; @property (strong,nonatomic) IBOutlet UITextVIEw *txtvIEwAsk; -(IBAction)postbutton:(ID)sender; @property (nonatomic,retain) Nsstring *datestr; @property(nonatomic,retain) NSData *imageData; @property(nonatomic,retain) Nsstring *postLength; @end
.m部分
-(voID)post { NSMutableURLRequest *mutableurlrequest = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://www.alvinchuastudios.com/aNSWERED/insert_question.PHP"]]; // create the Method "POST" For POSTING the QUESTIION with IMAGES [mutableurlrequest sethttpMethod:@"POST"]; NSLog(@"the email is:%@",manage.transformEmail); NSLog(@"the cat is:%@",manage.transformCategorIEs); NSLog(@"the text is:%@",textvIEwText.text); // NSLog(@"the firstimage is:%ld",(long)imgFirstimg.tag); // NSLog(@"the secondimage is:%ld",(long)imgSecondimg.tag); // NSlog(@"the status is:%d",1); NSLog(@"the user is:%@",manage.transformname); NSLog(@"the user registered is:%@",datestr); //passing the string to the server Nsstring *qususerUpdate =[Nsstring stringWithFormat:@"email_ID=%@&cat=%@&q_text=%@&q_image1=%ld&q_image2=%ld&q_status=1&last_upd_by=%@&last_upd_timestamp=%@",manage.transformEmail,manage.transformCategorIEs,textvIEwText.text,(long)imgFirstimg.tag,(long)imgSecondimg.tag,manage.transformname,datestr,Nil]; //check the value that what we passed NSLog(@"the data Details is =%@",qususerUpdate); //Convert the String to Data NSData *data1 =[qususerUpdate dataUsingEnCoding:NSUTF8StringEnCoding]; //Apply the data to the body [mutableurlrequest sethttpBody:data1]; //Create the response and Error NSError *err; NSURLResponse *response; NSData *responseData =[NSURLConnection sendSynchronousRequest:mutableurlrequest returningResponse:&response error:&err]; Nsstring *resstr =[[Nsstring alloc]initWithData:responseData enCoding:NSASCIIStringEnCoding]; //This is for Response NSLog(@"got response==%@",resstr); }解决方法 我认为Ashu的回答将返回null.尝试这个
NSData *dataimage = [[NSData alloc] init];dataimage = UIImagePNGRepresentation(image);Nsstring *stringImage = [dataimage base64EncodedStringWithOptions:NSDataBase64EnCoding64CharacterlineLength];总结
以上是内存溢出为你收集整理的ios – 将UIImage转换为NSData,将NSData转换为NSString,以便将图像发布到服务器全部内容,希望文章能够帮你解决ios – 将UIImage转换为NSData,将NSData转换为NSString,以便将图像发布到服务器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)