Reputation: 21899
currently I am having following flow
i)
|-----------------
|( context app) |
| purchase coins |
| select how much|---->ii
| |
| |
| |
|________________|
ii)
|-----------------
|(cotext website)|
|copmany website |
| |
|again give all |
|prev params |--->iii
|sends these |
|params as POST |
|req |
|________________|
iii)
|-----------------
| ctx website |
| secure https |
| purchase coins |
| done |
| |
| |
| |
|________________|
In step one user selects some amount he wants to purchase . Then user is taken to company website where he again selects these options and then these parameters are posted as POST request to secure website and then user have to fill information about card etc.
What I want is to jump to secure website omitting company website but How to post these values to secure website and then show the response in Browser ???
UPDATE till now i have following code, it is giving HTTP 200 OK but content length is -1
public static void postData(String url, String coinsValue) throws ClientProtocolException, IOException {
byte[] result = null;
SchemeRegistry registry = new SchemeRegistry();
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URLUtil.guessUrl(url));
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
httppost.setHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux " + "i686; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)");
httppost.setHeader("Accept", "text/html,application/xml," + "application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("gae", CoreConstants.USERINFO.getName()));
nameValuePairs.add(new BasicNameValuePair("param1", "1"));
nameValuePairs.add(new BasicNameValuePair("quantity", "1"));
nameValuePairs.add(new BasicNameValuePair("g_noteParam", coinsValue));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
int StatusCode= response.getStatusLine().getStatusCode();
String stautsLine = response.getStatusLine().toString();
HttpEntity r_entity = response.getEntity();
if (r_entity != null) {
int contentLength = (int)r_entity.getContentLength();
result = new byte[(int) 10];
if (r_entity.isStreaming()) {
DataInputStream is = new DataInputStream(r_entity.getContent());
is.readFully(result);
// no load this result to webview
}
XMLResponseParser.writeXMLtoSDCard(result, "https_response.html");
}
}
}
Upvotes: 0
Views: 2214
Reputation: 21899
private final String URL_STRING = "https://www.paypal.com/checkout/";
public void postData() {
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("param1", "value1"));
nameValuePairs.add(new BasicNameValuePair("param2", "value2"));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL_STRING);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httppost);
String data = new BasicResponseHandler().handleResponse(response);
mWebView.loadDataWithBaseURL(httppost.getURI().toString(), data, "text/html", HTTP.UTF_8, null);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Upvotes: 0
Reputation: 522
Why are you even asking the user to select the options twice? Skip step 1 altogether
Upvotes: 1