我正在向服务器发送请求
NSMutableURLRequest
,如下所示,问题之一是一个包含'+'符号的电话号码参数被删除了。// Create the request.
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:myURL ]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
/**
add post
****/
[theRequest setHTTPMethod:@"POST"];
NSString *encodedfullNumberFinal= [ fullNumberFinal stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *append2URL=[NSString stringWithFormat:@"deviceType=%d&token=%@&mobileNumber=%@&code=%@",
1, token,
encodedfullNumberFinal
,myBid
];
[theRequest setHTTPBody:[append2URL
dataUsingEncoding:NSUTF8StringEncoding /*NSUnicodeStringEncoding*/]];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = /*[*/[NSMutableData data] /* retain]*/;
} else {
// Inform the user that the connection failed.
}
注意,我使用Tomcat和Java作为服务器端。有什么建议可以保留带有“+”符号的参数吗?