STHTTPRequest returning null

54 views Asked by At

I'm able to load this URL in a safari browser and see the JSON data I need, but this STHTTPRequest is returning null, making me not able to use the JSON, what is going wrong here? I am loading in safari

let url = "192.168.101.1:8080/api"
let request = STHTTPRequest.buildGET(URL(string: url), timeout: 15.0)!
2

There are 2 answers

0
DisplayName On BEST ANSWER

needed to add http:// to the beginning of the url, giving http://192.168.101.1:8080/api/status

2
dbaekajnr On

First of all check you are using the latest STHTTPRequest from CocoaPods STHTTPRequest.

Then you can simply use the following to initialise and call a request to the url. The result is obtained through body in completionBlock

guard let request = STHTTPRequest(urlString: url) else {return}
request.timeoutSeconds = TimeInterval(floatLiteral: 15.0)
request.completionBlock = { (headers, body) in
           print(body)
}
request.errorBlock = { (error) in
        // ...
}
request.startAsynchronous()