Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

wgzlwl/AndroidStudio-HTTPClient

Open more actions menu
 
 

Repository files navigation

AndroidStudio-HTTPClient

A Simple HTTTP Request client, that's requesting a string from a nodejs webserver.
Tux, the Linux mascot

Libraries:

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

Required configuration:

In MainActivity.java:

Change http://10.0.2.2:3000/ to your IP-Address, unless your webserver is localhost.
Rememberlocalhost:3000 -> Android recognize localhost as: 10.0.2.2
Check/edit ID for button: Button contactServerButton = findViewById(R.id.button1);

In AndroidManifest.xml

add android:usesCleartextTraffic="true"
add <uses-permission android:name="android.permission.INTERNET" />

In activity_main.xml

Check/edit ID button: android:id="@+id/button1"

File location: MainActivity.java: AndroidStudio-HTTPClient/app/src/main/java/com/example/clienttonodejs/MainActivity.java
File location: AndroidManifest.xml: AndroidStudio-HTTPClient/app/src/main/AndroidManifest.xml
File location: activity_main.xml: AndroidStudio-HTTPClient/app/src/main/res/layout/activity_main.xml


Code is adapted from: Android AsyncTask HTTP GET request Tutorial and Minimal clien-server example for Android and Node.js

About

Just a simple program that can send a HTTP request by clicking the "check" button. Programmed to connect through localhost. Check readme.md for more info.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 76.4%
  • Kotlin 23.6%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.