gpt4 book ai didi

android - android连接服务器的方法

转载 作者:行者123 更新时间:2023-11-29 14:42:44 24 4
gpt4 key购买 nike

如何将android连接到服务器(PC)并向其传递值

最佳答案

这是向服务器发送“id”和“name”的方法:


URL url = null;
try {
String registrationUrl = String.format("http://myserver/register?id=%s&name=%s", myId, URLEncoder.encode(myName,"UTF-8"));
url = new URL(registrationUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
Log.d("MyApp", "Registration success");
} else {
Log.w("MyApp", "Registration failed for: " + registrationUrl);
}
} catch (Exception ex) {
ex.printStackTrace();
}

关于android - android连接服务器的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2696190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com