D
D
Dima Grib2018-11-19 02:55:42
JSON
Dima Grib, 2018-11-19 02:55:42

Alamofire and Get request. How to implement correctly?

Friends tell me
1. There is such a request, in response to which I receive JSON

https://www.yandexxx.com/graphql/query/?query_hash=60b755363b5c2301113477777&variables={%22reel_ids%22:[%227542607987%22],%22tag_names%22:[],%22location_ids%22:[],%22highlight_reel_ids%22:[],%22precomposed_overlay%22:false,%22show_header_follow_button%22:true}

2. Tried to do it by
guard var url = URLComponents(string: str) else { return }
    url.queryItems = [
            URLQueryItem(name: "query_hash=", value: "\(queryHash)"),
            URLQueryItem(name: "\(str2)variables", value: "{"),
            ....]

3. After that, I did the replacement of elements for the correct ulr through
url.percentEncodedQuery = url.percentEncodedQuery?.replacingOccurrences(of: "%3D=", with: "=")
    url.percentEncodedQuery = url.percentEncodedQuery?.replacingOccurrences(of: "%2522", with: "%22")

4. With percentEncodedQuery on chars such as - {} []everything crashes
5. I also tried to do everything in another way
var urlString: String = "https://www.yandexxx.com"
urlString = urlString.appendingFormat("/graphql/query/?query_hash=" + "\(queryHash)")
        urlString = urlString.appendingFormat("&variables={")
        urlString = urlString.appendingFormat("%22reel_ids%22:[\(userId)],")
        ........")

But I can't complete this task correctly. I would be grateful for hints

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Semchenko, 2018-11-19
@0xcffaedfe

Hint: GraphQL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question