Subversion Repositories SmartDukaan

Rev

Rev 10163 | Rev 10397 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10138 vikram.rag 1
package in.shop2020;
2
 
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStreamReader;
6
import java.io.UnsupportedEncodingException;
7
import java.util.ArrayList;
8
import java.util.List;
9
 
10
import org.apache.http.HttpResponse;
11
import org.apache.http.NameValuePair;
12
import org.apache.http.client.ClientProtocolException;
13
import org.apache.http.client.entity.UrlEncodedFormEntity;
14
import org.apache.http.client.methods.HttpGet;
15
import org.apache.http.client.methods.HttpPost;
16
import org.apache.http.impl.client.DefaultHttpClient;
17
import org.apache.http.message.BasicNameValuePair;
18
 
19
public class UpdateSDIUsingPanel {
20
	private static DefaultHttpClient client = new DefaultHttpClient();
21
	public static void main(String... args) throws ClientProtocolException, IOException{
10162 vikram.rag 22
		UpdateSDIUsingPanel UDSI = new UpdateSDIUsingPanel();
23
		UDSI.updateInventory(308L,"SDL061548809");
10138 vikram.rag 24
 
25
	}
10162 vikram.rag 26
	int updateInventory(long stock,String supc) throws ClientProtocolException, IOException{
10138 vikram.rag 27
		HttpPost post = new HttpPost("http://seller.snapdeal.com/inventory/update");
28
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
29
		nameValuePairs.add(new BasicNameValuePair("availableInventory",
30
				String.valueOf(stock)));
31
		nameValuePairs.add(new BasicNameValuePair("id",
32
				supc));
33
		nameValuePairs.add(new BasicNameValuePair("oper","edit"));
34
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
35
		HttpResponse response = client.execute(post);
36
		BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
37
		String line = "";
38
		while ((line = rd.readLine()) != null) {
39
			System.out.println(line);
40
		}
41
		return 1;
42
	}
43
 
10166 vikram.rag 44
	public void handleLogin() throws ClientProtocolException, IOException{
10138 vikram.rag 45
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
46
		HttpResponse response = null;
47
		try {
48
			response = client.execute(get);
49
		} catch (ClientProtocolException e) {
50
			e.printStackTrace();
51
		} catch (IOException e) {
52
			e.printStackTrace();
53
		}
54
		BufferedReader rd = null;
55
		try {
56
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
57
		} catch (IllegalStateException e1) {
58
			e1.printStackTrace();
59
		} catch (IOException e1) {
60
			e1.printStackTrace();
61
		}
62
		String line = "";
63
		StringBuffer sb = new StringBuffer();
64
		try {
65
			while ((line = rd.readLine()) != null) {
66
				sb.append(line);
67
			}
68
		} catch (IOException e) {
69
			e.printStackTrace();
70
		}
71
		int i= sb.toString().indexOf("name=\"lt\" value=");
72
		char[] charArray = sb.toString().toCharArray();
73
		String lt = "";
74
		int j=0;
75
		for(j=i+16;j<=charArray.length;j++){
76
 
77
			if(charArray[j]==' '){
78
				break;
79
			}
80
		}
81
		lt = sb.substring(i+17,j-1);
82
		System.out.println("LT VALUE " + lt);
83
		i= sb.toString().indexOf("name=\"execution\" value=");
84
		charArray = sb.toString().toCharArray();
85
		String ex = "";
86
		j=0;
87
		for(j=i+24;j<=charArray.length;j++){
88
			if(charArray[j]==' '){
89
				break;
90
			}
91
		}
92
		ex = sb.substring(i+24,j-1);
93
		System.out.println("EXECUTION VALUE " + ex);
94
		HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
95
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
96
		//nameValuePairs.add(new BasicNameValuePair("username",
97
		//"khushal.bhatia@saholic.com"));
98
		nameValuePairs.add(new BasicNameValuePair("username",
99
		"saholic-snapdeal@saholic.com"));
100
		//nameValuePairs.add(new BasicNameValuePair("password",
101
		//"sonline"));
102
		nameValuePairs.add(new BasicNameValuePair("password",
103
		"bc452ce4"));
104
		nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
105
		nameValuePairs.add(new BasicNameValuePair("execution",ex));
106
		nameValuePairs.add(new BasicNameValuePair("lt",lt));
107
		nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
108
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
109
		response = client.execute(post);
110
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
111
		line = "";
112
		while ((line = rd.readLine()) != null) {
113
			System.out.println(line);
114
		}
115
		get = new HttpGet("http://seller.snapdeal.com/inventory/");
116
		response = client.execute(get);
117
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
118
		while ((line = rd.readLine()) != null) {
119
			//System.out.println(line);
120
		}
121
	}
122
 
123
 
124
 
125
 
126
}