Resolved #6490 - custom User-Agent for requests

Also solved default port override, which is not ideal
This commit is contained in:
Yair Morgenstern 2022-04-06 23:17:53 +03:00
parent 9ef42f2a56
commit 5a368e47d9

View File

@ -1,6 +1,7 @@
package com.unciv.logic.multiplayer
import com.badlogic.gdx.Net
import com.unciv.UncivGame
import java.io.BufferedReader
import java.io.DataOutputStream
import java.io.InputStreamReader
@ -15,7 +16,6 @@ object SimpleHttp {
fun sendRequest(method: String, url: String, content: String, action: (success: Boolean, result: String)->Unit) {
var uri = URI(url)
if (uri.host == null) uri = URI("http://$url")
if (uri.port == -1) uri = URI(uri.scheme, uri.userInfo, uri.host, 8080, uri.path, uri.query, uri.fragment)
val urlObj: URL
try {
@ -27,6 +27,7 @@ object SimpleHttp {
with(urlObj.openConnection() as HttpURLConnection) {
requestMethod = method // default is GET
setRequestProperty("User-Agent", "Unciv/${UncivGame.Current.version}-GNU-Terry-Pratchett")
try {
if (content.isNotEmpty()) {