0

I need to make a URL with query parameter with large bracket. this is the example.

https://samlpe.com/detail?item_code[]=smtwGBArkp3ByfrLK3KfxdoX

I trying to use URLComponents and URLQueryItem. but URLQueryItem don't take array (["code"] in below) as a value.

var urlComponents = URLComponents(url: URL(string: "https://samlpe.com/detail")!,
                                                        resolvingAgainstBaseURL: false)
        urlComponents.queryItems = [URLQueryItem(name: "item_code", value: ["code"])]

Does anybody hove idea for that?

hiroshi046
  • 33
  • 5

2 Answers2

1

The [] has no special meaning. This is just:

URLQueryItem(name: "item_code[]", value: "smtwGBArkp3ByfrLK3KfxdoX")
Alexander
  • 59,041
  • 12
  • 98
  • 151
0

As @Alexander mentioned

URLQueryItem(name: "item_code[]", value: "smtwGBArkp3ByfrLK3KfxdoX")

was enough for this.

hiroshi046
  • 33
  • 5