iOS 8.3更新后NSMutableURLRequest正文格式错误

编程入门 行业动态 更新时间:2024-10-27 20:25:20
本文介绍了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正文格式错误

本文发布于:2023-11-26 22:41:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635498.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   格式   正文   iOS   NSMutableURLRequest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!