Java/Android class for easy web service requests. Response can be plain text or JSON. Uses HttpUrlConnection
Java
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
serviceclient
.gitignore
CODE_OF_CONDUCT.md
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
proguard-rules.pro
settings.gradle

README.md

ServiceRequest

A utility Java class developed for Android to handle easy web service requests. The response can be plain text or JSON. For the low level connection HttpUrlConnection is used.

Features

  • easy handling of POST and GET requests
  • supports String or JSONObject as response types
  • supports Multipart-Form-Data POST for uploading files

How to include the dependency using JitPack.io

Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

dependencies {
	        compile 'com.github.behringer24:ServiceClient:1.1'
	}

Example code

String es response

ServiceClient service = new ServiceClient("http://yoursite.com/api/service", RequestMethod.POST);
service.addParameter("name", "Max Mustermann");
service.addParameter("email", "max@mustermann.com");

try {
	String response = service.request();
} catch {IOException e} {
	// handle connection errors
}

JSONObject as response

ServiceClient service = new ServiceClient("http://yoursite.com/api/jsonService", RequestMethod.POST);
service.addParameter("name", "Max Mustermann");
service.addParameter("email", "max@mustermann.com");

try {
	JSONObject response = service.requestJson();
} catch {IOException e} {
	// handle connection errors
} catch {JSONException e}
	// handle JSON parse errors
}

Please remember to put network access in AsyncTask to keep it out of the UI-thread