NSURL returns Nil Value

前端 未结 2 1428
野的像风
野的像风 2020-12-11 16:08

Here Below is my code

NSString *string    = [NSString stringWithFormat:@\" http://abc.com  /Demo/View.php?drinkId=%@&name=%@&comment=%@&date=%@&         


        
相关标签:
2条回答
  • 2020-12-11 16:56

    NSURL will return nil for URLs that contain illegal chars, like spaces.

    Before using your string with [NSURL URLWithString:] make sure to escape all the disallowed chars by using [NSString stringByAddingPercentEscapesUsingEncoding:].

    Here is the class reference for NSString.

    0 讨论(0)
  • 2020-12-11 16:56

    Hi All Now My Problem Is solved here I did a mistake left a blank space before "http".

    The correct code is

    NSString *string    = [NSString stringWithFormat:@"http://myserver.com/Demo/View.php?drinkId=%@&name=%@&comment=%@&date=%@&rating=%@&ReqestType=SubmitComment",DrinkId,Name,Comment,Date,Rating];
    
    NSURL *url          = [[NSURL alloc] initWithString:string];
    
    0 讨论(0)
提交回复
热议问题