1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
   |  
 
package main;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
 
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
 
public class PostClassifiedAdsTest {
 
	public void PosterAnnonce (){		
		HttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost("http://www2.leboncoin.fr/ai/verify/2");
		try {
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
			nameValuePairs.add(new BasicNameValuePair("region", "Picardie"));
			nameValuePairs.add(new BasicNameValuePair("dpt_code", "Aisne"));
			nameValuePairs.add(new BasicNameValuePair("zipcode", "02200"));
			nameValuePairs.add(new BasicNameValuePair("category", "15"));
			nameValuePairs.add(new BasicNameValuePair("company_ad", "0"));
			nameValuePairs.add(new BasicNameValuePair("type", "s"));
			nameValuePairs.add(new BasicNameValuePair("name", "test"));
			nameValuePairs.add(new BasicNameValuePair("email", "test@test.fr"));
			nameValuePairs.add(new BasicNameValuePair("phone", "0600000000"));
			nameValuePairs.add(new BasicNameValuePair("no_salesmen", "1"));
			nameValuePairs.add(new BasicNameValuePair("subject", "test de sujet"));
			nameValuePairs.add(new BasicNameValuePair("body", "test de message"));
			nameValuePairs.add(new BasicNameValuePair("price", "1"));
			nameValuePairs.add(new BasicNameValuePair("cmd_photosup", "on"));
 
			post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 
			HttpResponse response = client.execute(post);
			BufferedReader rd = new BufferedReader(new InputStreamReader(
					response.getEntity().getContent()));
			String line = "";
			while ((line = rd.readLine()) != null) {
				System.out.println(line);
			}
 
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
 
} | 
Partager