NSMutableURLRequest带有URLencode的POST字符串数据,返回“414请求URI太大”

问题描述:

当我使用NSMutableURLRequest向URL字符串数据发送URLencode时,返回“414 Request-URI太大”,我该怎么办? 返回错误消息为如下:NSMutableURLRequest带有URLencode的POST字符串数据,返回“414请求URI太大”

<html> 
<head><title>414 Request-URI Too Large</title></head> 
<body bgcolor="white"> 
<center><h1>414 Request-URI Too Large</h1></center> 
<hr><center>nginx/1.0.6</center> 
</body> 
</html> 

我用NSMutableURLRequest设置如下:

NSURL *url = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ]]; 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
[request setHTTPMethod:@"POST"]; 
[request setHTTPBody:[urlStr dataUsingEncoding:NSUTF8StringEncoding]]; 
+0

你的URL有多长? –

+0

我用[urlStr长度]得到的长度是42833. –

+0

为什么这么大的一串? – Zigglzworth

urlstr不能既URL和POST数据必须在拆呢还是先&到URL和POST数据。?。

+0

hi ott,如何分割它?或第一个&到URL和POST数据? http://*.*.*/m/?r = Iphone/Suggest&C =%@&PN =%@&Flag =%@并且Suggest&C =%@数据太长,我如何拆分? –

+0

使用[urlStr componentsSeperatedByString:@“&”]将其拆分为一个数组,array [0]是url。然后再次使用[array componentsJoinedByString:@“&”]从array [1] .. array [n]重建后数据。当然,如果您在构建后期数据时只是省略了网址,那就更容易了。 –