2017-06-22 28 views
3

目前我在簡單的機器人工作,將有一個電報界面。問題是,finagle有辦法使http請求,但我不知道如何使https請求。 我試圖使HTTPS請求使用Scala庫欺騙來電報機器人API: 如何使用Finagle發送正確的https請求到電報API

val service: Service[http.Request, http.Response] = Http.client.withTlsWithoutValidation.newService("api.telegram.org:443") 
val request = http.Request(http.Method.Get,bottoken + "/getMe") 
request.host = "api.telegram.org" 
val t = Await.result(service(request) onSuccess(a => a) onFailure(exc => println("Auth check failed : " + exc.toString))) 
if (t.status == Status.Ok) { 
    println("Auth check success") 
} else { 
    println("Auth check failed : " + t.toString + "\r\n" + t.contentString) 
} 

每次我運行這段代碼它產生400錯誤的請求的HTTP響應。

Http.client.withTls("api.telegram.org") 

產生相同的結果。 我在做什麼錯?

回答

0

您必須在請求中添加http協議。

val request = http.Request(http.Method.Get, "http://yourholeHost/getMe") 
相關問題