1

I have the following request code written (using the SwiftHTTP library)

func performTagRequest(detail : String){
    var request = HTTPTask()
    var formattedDetail = detail.stringByReplacingOccurrencesOfString("\"", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
    var url = "www.gifbase.com/tag/\(formattedDetail)?format=json"

    url = url.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
    println(url)
    request.GET(url, parameters: nil, success: {(response: HTTPResponse) in
    if response.responseObject != nil {
        let data = response.responseObject as NSData
        let str = NSString(data: data, encoding: NSUTF8StringEncoding)!
        let gifMetaArray = str.componentsSeparatedByString(",") as [String]
        //println("response: \(gifMetaArray))") //prints the HTML of the page
    }
    },failure: {(error: (NSError, HTTPResponse?)) in
        println("error: \(error)")
    })
}

that returns a valid response in browser (ex for "10thingsihateaboutyou") but returns the error

error: (Error Domain=NSURLErrorDomain Code=-1002 "The operation couldn’t be completed. 
(NSURLErrorDomain error -1002.)" UserInfo=0x7ff22947b640 
{NSErrorFailingURLStringKey=www.gifbase.com/tag/10thingsihateaboutyou?format=json, 
NSUnderlyingError=0x7ff22940d550 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork
error -1002.)", NSErrorFailingURLKey=www.gifbase.com/tag/10thingsihateaboutyou?format=json}, nil)

I found that error -1002 is NSURLErrorUnsupportedURL and can be caused by not properly escaping characters, but the line above my print should do that I believe.

Anyone have any experience with this?

kidCoder
  • 354
  • 4
  • 17

1 Answers1

3

I found the answer by fiddling some more. I forgot "http://" because I have been coddled by desktop browsers...

kidCoder
  • 354
  • 4
  • 17