Mark
Mark

Reputation: 5088

HTTP POST request failing

I'm integrating with Adyen Payments. I do a HTTP POST to Adyen when going through 3D Secure. The CURL is:

curl 'https://test.adyen.com/hpp/3d/validate.shtml'
    -H 'Content-Type: application/x-www-form-urlencoded'
    --data 'PaReq=eNpVUttygjAQ%2FRXrBxAIRFJmzQxix%2FqAMi196FOHiVukI6AB6uXrm6DUNk979nJ292wg3SrE%2BSvKTqGAGJsmy3FUbKbjgHOXUZ85vjvhlDN7LCAJX%2FAg4BtVU9SVcCzbokAGqMuV3GZVKyCTh9lyJZhDXQ%2FIDUGJajkXKTZtUpahPHSFQgXk6oYqK1G8hR9h9BBEO9Ssi%2BKzjdYxkD4Esu6qVp2F6%2BumA4BO7cS2bfdNQMjxeLRkX5rrUkvWJRATB3IfLemM1Wi%2BU7ER63l%2BWaVLd5U%2BufHl3Yu%2FcicO%2BzcFYjJgk7UoqO1wm1E%2BcryA0sDjQHo%2FZKUZRCxmyYgxy7b1tlcP7E2j8AoYM5G%2FHtCKK6zkWXA60esMCPC0ryvUGXrJXxvIfezo2egrW60Zo0ZgNvH5oz1I3QcMS6HV0UPznsYAIKaU3I5IbsfW1r9P8AOBB62l&MD=djIhMWpWZmsxZE5LTFNJYmc5M1ByREFXQT09Ida8tar2LvClbYMvLrtnpYmd9QF91lL5tq1ggkf7cT4KB8uV7hNmv%2FAUfzhuny5nQAkEJCcEpHyxtG%2Fz33mwGDJYJw117NxfSMV64R3FIHfYyTLorMXd656CVrnCFQ5fLtxHiCjLSuNouwNqE03E8PXLmzVCMBGJx%2B8IGCkm%2F3rvXZwucOwtM94uFqm7atGsIEmZ%2F4HW05a9m3YkGBpA1p4CR8x59F2AQSrmIQXfxwswpKvVxV%2FOLZoO4CEgMV3gzSu2Bb2AsfR3p1ZCBXUPh8KvEaiBcQ%2FwPq%2FnGypRHFCSOabqlqUwUWyXAQF%2FtU8g0iVaLOvnucrunQ8%3D&TermUrl=http%3A%2F%2Flocalhost%3A8080%2Fv1%2Fgift%2Fpaymentresponse%2F5aaff1fc-bb84-4f84-8530-54cdc273ddb3'
    -i

Running this returns a HTML form and a status code of 200.

Now I want to write an integration test for this. I'm doing:

HttpPost httpPost = new HttpPost( "https://test.adyen.com/hpp/3d/validate.shtml" );
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("MD", "djIhMWpWZmsxZE5LTFNJYmc5M1ByREFXQT09Ida8tar2LvClbYMvLrtnpYmd9QF91lL5tq1ggkf7cT4KB8uV7hNmv%2FAUfzhuny5nQAkEJCcEpHyxtG%2Fz33mwGDJYJw117NxfSMV64R3FIHfYyTLorMXd656CVrnCFQ5fLtxHiCjLSuNouwNqE03E8PXLmzVCMBGJx%2B8IGCkm%2F3rvXZwucOwtM94uFqm7atGsIEmZ%2F4HW05a9m3YkGBpA1p4CR8x59F2AQSrmIQXfxwswpKvVxV%2FOLZoO4CEgMV3gzSu2Bb2AsfR3p1ZCBXUPh8KvEaiBcQ%2FwPq%2FnGypRHFCSOabqlqUwUWyXAQF%2FtU8g0iVaLOvnucrunQ8%3D&TermUrl=http%3A%2F%2Flocalhost%3A8080%2Fv1%2Fgift%2Fpaymentresponse%2F5aaff1fc-bb84-4f84-8530-54cdc273ddb3"));
params.add(new BasicNameValuePair("PaReq", "eNpVUttygjAQ%2FRXrBxAIRFJmzQxix%2FqAMi196FOHiVukI6AB6uXrm6DUNk979nJ292wg3SrE%2BSvKTqGAGJsmy3FUbKbjgHOXUZ85vjvhlDN7LCAJX%2FAg4BtVU9SVcCzbokAGqMuV3GZVKyCTh9lyJZhDXQ%2FIDUGJajkXKTZtUpahPHSFQgXk6oYqK1G8hR9h9BBEO9Ssi%2BKzjdYxkD4Esu6qVp2F6%2BumA4BO7cS2bfdNQMjxeLRkX5rrUkvWJRATB3IfLemM1Wi%2BU7ER63l%2BWaVLd5U%2BufHl3Yu%2FcicO%2BzcFYjJgk7UoqO1wm1E%2BcryA0sDjQHo%2FZKUZRCxmyYgxy7b1tlcP7E2j8AoYM5G%2FHtCKK6zkWXA60esMCPC0ryvUGXrJXxvIfezo2egrW60Zo0ZgNvH5oz1I3QcMS6HV0UPznsYAIKaU3I5IbsfW1r9P8AOBB62l"));
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();

However I keep getting a status of 500 back. How can I replicate this simple CURL from Java?

The response is:

HttpResponseProxy{HTTP/1.1 500 Internal Server Error [Date: Mon, 28 May 2018 19:38:21 GMT, Server: Apache, Set-Cookie: JSESSIONID=3AD3E57C6A509938B790B6EFB237AA20.test104e; Path=/hpp; Secure; HttpOnly, P3P: policyref="/w3c/policy.xml", CP="NOI DSP COR CURa ADMa DEVa OUR NOR BUS FIN STA", Strict-Transport-Security: max-age=31536000, Content-Security-Policy-Report-Only: default-src 'self' https://*.adyen.com; script-src 'self' 'unsafe-inline' https://*.adyen.com; style-src 'self' 'unsafe-inline' https://*.adyen.com; img-src *; font-src *; object-src 'none'; frame-src 'self' https://*.adyen.com; form-action 'self' https://*.adyen.com; base-uri https://*.adyen.com; report-uri /hpp/csp;, Content-Length: 15699, Connection: close, Content-Type: text/html;charset=UTF-8] ResponseEntityProxy{[Content-Type: text/html;charset=UTF-8,Content-Length: 15699,Chunked: false]}}

EDIT

Im on a mac and have been unable to get fiddler to work through mono. Tried Wireshark but far too low-level. Also tried Charles Web Proxy but that does not pick up the request, despite all solutions saying to add above the code to be run:

 System.setProperty("http.proxyHost", "localhost");
 System.setProperty("http.proxyPort", "8888");

EDIT

I have found the request with Wireshark but everything is encrypted so cannot see request body.

Upvotes: 0

Views: 368

Answers (2)

Mark
Mark

Reputation: 5088

I achieved like so:

HttpPost httpPost = new HttpPost( "https://test.adyen.com/hpp/3d/validate.shtml" );
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
String payload = String.format("PaReq=%s&MD=%s&TermUrl=%s", URLEncoder.encode(paReq, "UTF-8"), URLEncoder.encode(md, "UTF-8"), URLEncoder.encode(termsUrl, "UTF-8"));
StringEntity body = new StringEntity(payload,
        ContentType.APPLICATION_FORM_URLENCODED);
httpPost.setEntity(body);
HttpResponse authResponse = httpclient.execute(httpPost);

Upvotes: 0

DavidW
DavidW

Reputation: 1421

This is just a guess, but I suspect you're probably running into a problem with URL-encoding your parameter values. (Which appear to already be URL encoded, based on %2F.)

Try passing the un-encoded values to the BasicNameValuePair constructor.

Upvotes: 1

Related Questions