Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 与Vapor客户端抗争_Swift_Http_Client_Vapor - Fatal编程技术网

Swift 与Vapor客户端抗争

Swift 与Vapor客户端抗争,swift,http,client,vapor,Swift,Http,Client,Vapor,我正试图从我的vapor web服务向GooglePlacesAPI发出一个简单的get请求 这就是我的控制器的外观: import Vapor import HTTP import VaporPostgreSQL final class MainController { var currentDroplet: Droplet! func addRoutes(drop: Droplet) { currentDroplet = drop drop.get("places",

我正试图从我的vapor web服务向GooglePlacesAPI发出一个简单的get请求

这就是我的控制器的外观:

import Vapor
import HTTP
import VaporPostgreSQL

final class MainController {

var currentDroplet: Droplet!

func addRoutes(drop: Droplet) {

    currentDroplet = drop
    drop.get("places",String.self, String.self, handler: getNearbyPlaces)

}

func getNearbyPlaces(request: Request, lat: String, long: String) throws -> ResponseRepresentable {

    let googleAPIKey = "MY_KEY"
    let googlePlacesBaseURL = "https://maps.googleapis.com/maps/api/place/nearbysearch"

    let url = googlePlacesBaseURL + "/json?location=\(lat),\(long)&radius=500&types=food&key=" + googleAPIKey

    print(url)

    let apiResponse = try drop.client.get(url)

    print(apiResponse)

    return apiResponse.json != nil ? apiResponse.json! : "Something went bad"


   }
}
它应该是这么简单,但是当我调用它时,请求一直挂起很长一段时间,然后返回500。 请注意,控制台中打印的url直接在浏览器中工作正常。
我无法找到一个有用的方法来捕获和调试任何错误。

< P>我需要添加导入基础和DROPclie=基础客户端。p> url编码正确吗?是的。登录到控制台的url在浏览器中工作正常浏览器将url自身转换为正确的格式-如果您通过程序调用,可能需要对其进行编码在命令行上使用curl调用它,那么它也应该工作正常。这似乎和Vapor客户端文档中描述的完全一样:就是这样。就像魔术一样。谢谢!真不敢相信他们没有在文档中指定drop.client是出租的。它不能被分配。还有其他解决办法吗?