Recently I want use a search interface.But I am confused by the request body. According to reference,when you need to search in their site,you can do like this:
curl -d "keyword=android" http://gankio.herokuapp.com/search
So how to post a this request in java rather than curl?
I have tried useing okhttp.
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
OkHttpClient client = new OkHttpClient();
String json = "keyword=android";
RequestBody body = RequestBody.create(JSON,json);
Request request = new Request.Builder()
.url("http://gankio.herokuapp.com/search")
.post(body)
.build();
try {
Response response = client.newCall(request).execute();
Log.d("TAG",response.body().string());
} catch (IOException e) {
e.printStackTrace();
}
}
});
thread.start();`