iOS 8.3更新后NSMutableURLRequest正文格式错误 [英] NSMutableURLRequest body malformed after iOS 8.3 update

查看:99
本文介绍了iOS 8.3更新后NSMutableURLRequest正文格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在今天的iOS 8.3更新之前,我的代码工作正常,但在更新服务器后开始拒绝请求,因为它无法找到JSON数据。

Before today's iOS 8.3 update I had my code working right, but after updating server started rejecting requests as it could not find JSON data.

我发现iOS发送错误的应用程序/ x-www-form-urlencoded文本(未正确编码,因为它似乎是JSON对象):

I found that iOS is sending a wrong application/x-www-form-urlencoded text (not properly encoded as it seems a JSON object):

这是我期望发送的内容(以及8.2发送的内容):

This is what I expected to be sent (and what was sent on 8.2):

正如我所说的,这只发生在iOS 8.3上(我刚刚在iOS模拟器上尝试过8.2并且它可以工作)。

As I said, this only happens on iOS 8.3 (I just tried on iOS simulator with 8.2 and it works).

我认为问题出现在这些行中的一个类中:

I think the problem is in one of the classes that appear on these lines:

NSData *bodyData = [NSJSONSerialization dataWithJSONObject:requestDict options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPBody = bodyData;

我检查了Apple文档,最近没有出现修改。

I checked Apple documentation and none appears as modified recently.

是否有人遭受同样的痛苦或知道是什么导致了这一点?

Is someone suffering the same or knows what can lead to this?

谢谢。

推荐答案

我把评论作为答案放在这里:

I put the comment as answer here:

尝试指示http方法,如

Try to indicate the http method like

[request setHTTPMethod:@"POST"]

和/或,请求长度

[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 

和/或内容类型

[request setValue:@"application/<YOUR CONTENT TYPE>"forHTTPHeaderField:@"Content-Type"];

这篇关于iOS 8.3更新后NSMutableURLRequest正文格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆