hey Folks,
I got an issue and it driving me nuts. I am posting from a form to my Spring MVC 3 controller. Internally I am posting to paypal.
GOAL: To display the page that shows the item and the price charged to the customer.
What I keep getting is: "Please login to use the PayPal Sandbox features." WHEN I use the test url:
https://www.sandbox.paypal.com/cgi-bin/webscr
AND I get: "You have requested an outdated version of PayPal. This error often results from the use of bookmarks." when I use the official URL: https://www.paypal.com/cgi-bin/webscr
SO I am arriving at the paypal site its JUST that it keeps asking me to login OR giving me that "outdated version bookmark error". I did login through my browser so apparently a cookie is set in the browser, but this is posting through Java....Code:String url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; //url = "https://www.paypal.com/cgi-bin/webscr"; //url = "https://developer.paypal.com"; //url = "https://www.paypal.com/cgi-bin/webscr"; //HttpParams httpParams = new BasicHttpParams(); //HttpClient client = new DefaultHttpClient(httpParams); HttpPost httpPost = new HttpPost(url); // MIMIC BROWSER //conn.setRequestProperty( "Host", "test.com"); //httpPost.setHeader( "User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"); httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows; U;Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7"); //conn.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0"); //httpPost.setHeader( "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); httpPost.setHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); httpPost.setHeader( "Accept-Language", "en-us,en;q=0.5"); //conn.setRequestProperty( "Keep-Alive", "115"); //conn.setRequestProperty( "Connection", "keep-alive"); //httpPost.setHeader("Content-type", "application/x-www-form-urlencoded"); List <NameValuePair> nvps = new ArrayList <NameValuePair>(); //nvps.add(new BasicNameValuePair("method", "password")); nvps.add(new BasicNameValuePair("cmd", "_s-xclick")); //nvps.add(new BasicNameValuePair("cmd", "_xclick")); //nvps.add(new BasicNameValuePair("hosted_button_id", "31991")); //client.getParams().setParameter("on0", "$20.00"); //<input type="hidden" name="business" value="your@paypalaccount.com"> nvps.add(new BasicNameValuePair("business", "dev_12223345765_biz@logixplayer.com")); //nvps.add(new BasicNameValuePair("business", "asim@logixplayer.com")); //<input type="hidden" name="currency_code" value="USD"> nvps.add(new BasicNameValuePair("currency_code", "USD")); //Amount: <br /><input name="amount" type="text" id="amount" size="45"> nvps.add(new BasicNameValuePair("amount", "4")); nvps.add(new BasicNameValuePair("item_name", "PiT words")); nvps.add(new BasicNameValuePair("no_note", "1")); nvps.add(new BasicNameValuePair("return", "http://localhost:8080/pit-web-0.0.1-SNAPSHOT/welcome")); //nvps.add(new BasicNameValuePair("IDToken2", "password")); try { httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } HttpResponse response = null; HttpClient client = new DefaultHttpClient(); try { response = client.execute(httpPost); HttpEntity entity = response.getEntity(); entity = response.getEntity(); if (entity != null) { System.out.println(EntityUtils.toString(entity)); entity.consumeContent(); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
I suspect it has something to do with the headers because if I remove some of the values I get an exception...anyone know whats going on???
Code:httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows; U;Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7"); //conn.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0"); //httpPost.setHeader( "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); httpPost.setHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); httpPost.setHeader( "Accept-Language", "en-us,en;q=0.5");
Ultimately I just want the paypal page to show with the item and the price so the customer can buy....any help would be greatly appreciated.


Reply With Quote
