小编cor*_*can的帖子

NSData和iOS上的POST上传图像

我一直在梳理很多关于在iOS上通过POST上传图片的帖子.尽管有关此主题的大量信息,但我无法正确上传从我的iPhone模拟器照片库中获取的JPEG数据.数据一旦在服务器上,就只是一串巨大的十六进制数据.NSData不应该只是一个字节流吗?我不知道所有的十六进制是什么,或者为什么这个代码似乎适用于其他所有人.

这是有问题的代码:

-(void)uploadWithUserLocationString:(NSString*)userLocation{
NSString *urlString = @"http://some.url.com/post";

// set up the form keys and values (revise using 1 NSDictionary at some point - neater than 2 arrays)
NSArray *keys = [[NSArray alloc] initWithObjects:@"auth",@"text",@"location",nil];
NSArray *vals = [[NSArray alloc] initWithObjects:self.authToken,self.textBox.text,userLocation,nil];

// set up the request object
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

//Add content-type to Header. Need to use a string boundary for data uploading.
NSString *boundary = [NSString stringWithString:@"0xKhTmLbOuNdArY"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; …
Run Code Online (Sandbox Code Playgroud)

iphone post nsdata nsurlrequest ios

37
推荐指数
3
解决办法
6万
查看次数

标签 统计

ios ×1

iphone ×1

nsdata ×1

nsurlrequest ×1

post ×1