Skip to content Skip to sidebar Skip to footer

How To Send Data To Server

I want to make a login. So how I send the username and the password to my server? I wrote a php script for the server. He will receive the username and the password and if the user

Solution 1:

You can use OkHttp to achieve this easily. In order to include the library use the following in dependencies: compile 'com.squareup.okhttp3:okhttp:3.2.0'

As a sample you can use it like this:

RequestBodyformBody=newFormBody.Builder()
                .add("username", USER_NAME)
                .add("password", PASSWORD)
                .build();
Requestrequest=newRequest.Builder()
        .url(url)
        .post(formBody)
        .build();
OkHttpClientclient=newOkHttpClient();

Responseresponse= client.newCall(request).execute();
if(response.code == 200){
StringresponseData= responses.body().string(); 
  //Process the response Data
  }else{
     //Server problem
  }

Solution 2:

You can communicate Android mobile client with the server. This tutorial is a brief guide on how to integrate your Android App to WAMP Server. This server could be hosted on you local machine or on a remote server.

Connecting your Android app to your WAMP server

Solution 3:

You will have to use any networking library like volley,Retrofit or you can also use Httpurlconnection to send data to server.Here is an example of sending data to server using httpurlconnection. https://www.studytutorial.in/android-httpurlconnection-post-and-get-request-tutorial

Solution 4:

Post a Comment for "How To Send Data To Server"