3

I have these parameters saved as string :

title=Culture, sport & recreation (1 day)&useremail=ammar@gmail.com&days=2&ispredefined=false&languageid=1&websiteid=1&node=item&languageid=1&websiteid=1&moduletype=Accommodation&moduleuniquename=abu.dhabi.plaza.hotel.apartments&dayindex=1

and I am passing it to a request body using the below code:

let request = NSMutableURLRequest(URL: URL.getURL(url)!)
        let session = NSURLSession.sharedSession()
        request.HTTPMethod = "POST"
        request.HTTPBody = params.dataUsingEncoding(NSASCIIStringEncoding)

but the problem is that the title in the string title=Culture, sport & recreation has '&'character and i am getting 400 bad Request from the server

please any advice how to solve this problem?

ammar arangy
  • 95
  • 1
  • 1
  • 9

1 Answers1

4

As you can read in the attached links you have to encode the ampersand sign.

encodeURIComponent('&') gives "%26"

Thus, you have to replace all ampersands with %26 or use encodeURIComponent(str) in your code.

escaping ampersand in url

How can I send the "&" (ampersand) character via AJAX?

Community
  • 1
  • 1