mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Resolved #6490 - custom User-Agent for requests
Also solved default port override, which is not ideal
This commit is contained in:
parent
9ef42f2a56
commit
5a368e47d9
@ -1,6 +1,7 @@
|
|||||||
package com.unciv.logic.multiplayer
|
package com.unciv.logic.multiplayer
|
||||||
|
|
||||||
import com.badlogic.gdx.Net
|
import com.badlogic.gdx.Net
|
||||||
|
import com.unciv.UncivGame
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.DataOutputStream
|
import java.io.DataOutputStream
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
@ -15,7 +16,6 @@ object SimpleHttp {
|
|||||||
fun sendRequest(method: String, url: String, content: String, action: (success: Boolean, result: String)->Unit) {
|
fun sendRequest(method: String, url: String, content: String, action: (success: Boolean, result: String)->Unit) {
|
||||||
var uri = URI(url)
|
var uri = URI(url)
|
||||||
if (uri.host == null) uri = URI("http://$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
|
val urlObj: URL
|
||||||
try {
|
try {
|
||||||
@ -27,6 +27,7 @@ object SimpleHttp {
|
|||||||
|
|
||||||
with(urlObj.openConnection() as HttpURLConnection) {
|
with(urlObj.openConnection() as HttpURLConnection) {
|
||||||
requestMethod = method // default is GET
|
requestMethod = method // default is GET
|
||||||
|
setRequestProperty("User-Agent", "Unciv/${UncivGame.Current.version}-GNU-Terry-Pratchett")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (content.isNotEmpty()) {
|
if (content.isNotEmpty()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user