I am using a dummy rest API server called json-server. I wrote an android app which is able to make POSt request to the server, server returns an expected 201 as well.
I am not very familiar with REST api. I want to send a File from my device
public void run() {
Logger.d("reponse","inside thread");
HttpClient client = new DefaultHttpClient(TunnelView.this);
String url = "http://some_server:3000/comments";
HttpGet get = new HttpGet(url);
HttpPost post = new HttpPost(url);
HttpResponse response = null;
post.setEntity(new FileEntity(new File("/root/sdcard/Download/File.txt"),"application/octect-stream"));
try
{
response = client.execute(post);
String res = response.getEntity().getContent().toString();
Logger.d("response", res);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Every time I do a post, a new Id is added under the Comments array on my json file located on the rest API server.
"comments": [
{
"id": 1,
"body": "some comment",
"postId": 1
},
{
"id": 2
},]
I am not sure how to change my android code or the REST API Post URl so I can send the whole text file content and it gets posted on the json file on the server.
localhost? Is the server on the Android device too?localhostproblem, how to you know that the server supports file upload?