首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NSURLRequest setHttpBody

NSURLRequest setHttpBody
EN

Stack Overflow用户
提问于 2012-05-25 06:20:07
回答 1查看 1.3K关注 0票数 0

我收到了一个错误的帖子(php:echo $_POST),如下所示:Array (电子邮件“aa@qq_com => =>Content: form-data;name=”密码“c8837b23ff8aaa8a2dde915473ce0991 )

我的代码:

代码语言:javascript
运行
复制
// set header value ,   some random text that will never occur in the body  
NSString *boundary = @"---------------------------14737809831466499882746641449";   NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];   [request addValue:contentType forHTTPHeaderField: @"Content-Type"];         /*   now lets create the body of the post      */   NSMutableData *body = [NSMutableData data];              //  email part         
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];        
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"email\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];   
[body appendData:[anEmail dataUsingEncoding:NSUTF8StringEncoding]];     
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];          //  password part     [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];     
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"password\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];    
[body appendData:[aPassword dataUsingEncoding:NSUTF8StringEncoding]];     
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];          //  image part     [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];        
[body appendData:[[NSString stringWithFormat: @"Content-Disposition: form-data; name=\"uploadingImage\"; filename=%@\r\n", anImageName]                        dataUsingEncoding:NSUTF8StringEncoding]];    
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];   
[body appendData:[NSData dataWithData:aFileData]];     
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];             
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];  
// setting the body of the post to the reqeust  
[request setHTTPBody:body];         // now lets make the connection to the web  
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-25 08:18:45

它应该是

代码语言:javascript
运行
复制
name=\"password\"\r\n\r\n%@",password];

但现在你这样做了

代码语言:javascript
运行
复制
name=\"password\"\r\n%@\r\n",password];

希望你明白这个错误..。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10749432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档