<project><id>1733</id></project><payment_detail><firstname></firstname><lastname></lastname><address>23 Bol Avenue</address><city>Bangalore</city><state>Karnataka</state><iso3166CountryCode>356</iso3166CountryCode><zip>560071</zip><creditCardNumber>9228722562782637</creditCardNumber><securityCode>212</securityCode><expiryDateMonth>12</expiryDateMonth><expiryDateYear>2019</expiryDateYear></payment_detail></donation>
private String getResponse(String URLStr) {
String requestXml = this.getRequestXml();
System.out.println(requestXml);
URL url = null;
try {
url = new URL(URLStr);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpURLConnection hConn = null;
try {
hConn = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
hConn.setRequestMethod("POST");
} catch (ProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
hConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
hConn.setDoInput(true);
hConn.setDoOutput(true);
hConn.setUseCaches(false);
hConn.setRequestProperty("Content-Language", "en-US");
hConn.setRequestProperty("Content-Length", ""
+ Integer.toString(requestXml.getBytes().length));
hConn.setAllowUserInteraction(true);
DataOutputStream printout = null;
try {
printout = new DataOutputStream(hConn.getOutputStream());
if(printout == null){
System.out.println("Something is Rotten");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
printout.writeBytes(requestXml);
printout.flush();
printout.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader in = null;
try {
in = new BufferedReader(new java.io.InputStreamReader(hConn
.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String line;
StringBuffer responseBuf = new StringBuffer("");
try {
while ((line = in.readLine()) != null) {
responseBuf.append(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(responseBuf.toString());
hConn.disconnect();
return responseBuf.toString();
}
I am passing the api_key in two places: in the params with the URL, aand within <auth_request> tags inside the XML.
Can someone tell me where I am going wrong? Once I see the response XML I can write the parser for it and close this.
I have masked the actual email ids and api key values,project ids etc, of course.