我正在向服务器发送请求,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。
有什么建议如何用“+”号保存参数?