0

Below is the string that I need to create as a url for GET request. I am always getting nil in NSURL. Can anyone help me ?

 http://example.com/webexternal1/api/Values/sendorder?orderlist={code:"122|155",rate:"60|5",qty:"5|5"}&tab=N2 //strParams = {code:122|155,rate:60|5,qty:5|5}&tab=N2 dataUrl = [@"http://example.com/webexternal1/api/Values/sendorder?orderlist=" stringByAppendingString:strParams]; urlComponants = [[NSURLComponents alloc]initWithString:dataUrl]; NSURL *url = urlComponants.URL; 
2
  • What's the exact value of strParams? Commented Dec 8, 2016 at 18:25
  • strParams = {code:122|155,rate:60|5,qty:5|5}&tab=N2 Commented Dec 8, 2016 at 18:31

1 Answer 1

1

Try url encoding the strParams.

NSString* strParams = [@"{code:122|155,rate:60|5,qty:5|5}&tab=N2" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
Sign up to request clarification or add additional context in comments.

2 Comments

This correct. But stringBy... is deprecated. Use the newer call.
Worked Thanks , This is the new method [strParams stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.