如何通过Android客户端中的特定端口连接到java服务器?

时间:2018-06-17 18:13:19

标签: android web-services okhttp

我正在使用OkHttpClient,我想通过端口443连接到服务器。

 public static String hostUrl = "http://ServerIP/";

 RequestBody formBody = new FormBody.Builder()
                        .add("username", mEmail)
                        .add("passcode", mPassword)
                        .build();
                Request request = new Request.Builder()
                        .url(Constant.hostUrl)
                        .post(formBody)
                        .build();
                OkHttpClient client = new OkHttpClient();
               try{
                Response response = client.newCall(request).execute();

                   if(response.code() == 200){
                       String responseData = response.body().string();
                       Log.w("responseData", responseData);
                       //Process the response Data
                   }else{
                       //Server problem
                       Log.w("server problem", "server problem");
                   }


               }catch(IOException ex) {
                    //Do something with the exception
                   ex.printStackTrace();
                   Log.w("send logi data to S Err",ex);
                }

1 个答案:

答案 0 :(得分:1)

只需将端口号附加到您的基本网址

http://ServerIP:443/