I am sending Json String to my webapi php file from Android Using OkHttpClient from background Service.
The Code of Web Service Is
if (isset($_POST)) {
$data = json_decode(file_get_contents('php://input'), true);
}
The Android Code is :
String requestString = jsonObject.toString();
URL url = new URL("http://cbs.octa.in/webapis/InsertData.php");
OkHttpClient client = new OkHttpClient();
MediaType mdt = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, requestString);
Request request = new Request.Builder()
.url(url)
.header("Content-Type","application/json")
.post(body)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.v("BGAPI", "RESPONSE ERROR " + e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.v("BGAPI", "RESPONSE " + response);
}
});
The output for this call i am getting is :
RESPONSE ERROR Unable to resolve host "cbs.octa.in": No address associated with hostname
I tried this call from postman and its working , even i confirmed by entering the same url in broweser.
My question is to send data to server in that web api. Please guide me.
Note : For Privacy i have not given the actual domain name.