小编Ste*_*eve的帖子

向NSMutableURLRequest添加参数时出现异常

在向POST请求添加xml正文时,我收到以下异常.在使用GET执行相同操作时,我得到了相同的异常.任何帮助,将不胜感激.

- (IBAction)buttonTapped:(id)sender {
NSLog(@"buttonTapped");

//Creating the request
NSMutableURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.1:9081/Transport/services/DriverService"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval: 30.0];
[ request setHTTPMethod: @"POST"];
//creating connection and sending it
NSURLConnection *connection = [ [NSURLConnection alloc] initWithRequest:request delegate:self];

NSString *xmlString = @"<Driver type=\"GetName\"><DriverID>1</DriverID></Driver>";

[request setHTTPBody:[xmlString 
                      dataUsingEncoding:NSUTF8StringEncoding]];

//checking if connection is good
if (connection){
    NSLog (@"Connection successfull!");
    self.responseData = [NSMutableData data];
}
else
{
    NSLog (@"Connection failed");
}
}
Run Code Online (Sandbox Code Playgroud)

例外

Exception:
2011-03-02 09:22:12.055 XML[1125:207] buttonTapped

2011-03-02 09:22:12.056 XML[1125:207] -[NSURLRequest setHTTPMethod:]: unrecognized selector sent to …
Run Code Online (Sandbox Code Playgroud)

iphone post get ipad

9
推荐指数
1
解决办法
3761
查看次数

标签 统计

get ×1

ipad ×1

iphone ×1

post ×1