ASI框架设置Content-Type无效的问题

来源:互联网 发布:众安保险尊享e生 知乎 编辑:程序博客网 时间:2024/06/06 20:13

我服务器的某些接口只接收Content-Type 为“application/x-protobuf”的访问,我是用ASIFormDataRequest向服务器发送数据,通过addRequestHeader:value:方法设置Content-Type,结果总是不成功,在服务器端发现收到的Content-Type为“application/octet-stream”,后来经过多番尝试,通过使用setRequestHeaders:批量设置http头可以生效,在此记录以下,代码如下,注释掉的部分就是不起效的。

        ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:nsurl];        [request setRequestMethod:@"POST"];        [request setPostBody:[cmtBuilder.build data]];        //通过以下设置content-type的方式不起效//        [request addRequestHeader:@"application/x-protobuf" value:@"Content-Type"];//        [request addRequestHeader:@"application/x-protobuf" value:@"Accept"];        //通过如下方式才可以        NSMutableDictionary *header = [[NSMutableDictionary alloc] init];        [header setValue:@"application/x-protobuf" forKey:@"Content-Type"];        [header setValue:@"application/x-protobuf" forKey:@"Accept"];        [request setRequestHeaders:header];                //启动同步访问        [request startSynchronous];