// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package routing.demo.client;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;

public class SendHttp {
    private static void send(String json) throws ClientProtocolException, IOException {
        HttpPost request = new HttpPost("http://localhost:8888/demo");
        request.setHeader("Content-Type", "json/text");
        request.setEntity(new StringEntity(json));
        HttpClient client = HttpClientBuilder.create().build();
        HttpResponse response = client.execute(request);
        System.out.println(response.getStatusLine().getStatusCode());
    }
    public static void main(String[] args) throws ClientProtocolException, IOException {
        send("{ \"ival\": 1, \"sval\": \"HTTP #1\" }");
        send("{ \"ival\": 2, \"sval\": \"HTTP #2\" }");
        send("{ \"ival\": 3, \"sval\": \"HTTP #3\" }");
    }
}
