package Demos;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class TestHttpPost {

	  public  List <NameValuePair> nvps = new ArrayList <NameValuePair>();
	
	public void getHttpPost(String URL) {
		CloseableHttpClient httpclient = HttpClients.createDefault();
		HttpPost httpPost = new HttpPost(URL);
		try {
	            List <NameValuePair> nvps = new ArrayList <NameValuePair>();
	            nvps.add(new BasicNameValuePair("roomid", "18898"));

	            httpPost.setEntity(new UrlEncodedFormEntity(nvps));
			
	            httpPost.addHeader("Cookie", "p1u_id=6bb0e3f8b88fe33229982462abdf5186f619a59e8ae4e81cd8c7cd822a0b925c562f0fa7ef303637");
			CloseableHttpResponse PostResponse = httpclient.execute(httpPost);
			try {
				HttpEntity entity = PostResponse.getEntity();
				String a = EntityUtils.toString(entity, "UTF-8");
				System.out.println(a);
				EntityUtils.consume(entity);
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				PostResponse.close();
			}
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				httpclient.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestHttpPost thp = new TestHttpPost();
		thp.getHttpPost("http://test.star.api.plu.cn/RoomSubscription/SubscribeRoom");
	}

}
