try
{
String xmlReq = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request_inquiry><partner_id>0999</ partner_id><terminal_type>6012</ terminal_ type><product_code>4001</product _code><date_time>20130715115100</date_time><trx_id>SDFSF11234424ADFA</trx_id><data><cust_id>030913320611</cust_id></data></request_inquiry>";
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
HttpPost httpPost = new HttpPost("202.169.43.53:52056/transaction");
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=ISO");
// httpPost.setHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(xmlReq.length()));
StringEntity se = new StringEntity(xmlReq, ContentType.TEXT_XML);
httpPost.setEntity(se);
System.out.println("Request>>"+httpPost);
StringBuilder html = new StringBuilder("");
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
if(httpResponse.getStatusLine().getStatusCode() != 200) {
InputStream in = httpResponse.getEntity().getContent();
byte b[] = new byte[1024] ;
while(in.read(b) != -1) {
html.append((new String(b)).toString());
b = new byte[1024];
}
System.out.println("Output HTML>> "+html.toString());
}
else{
InputStream in = httpResponse.getEntity().getContent();
byte b[] = new byte[1024] ;
while(in.read(b) != -1) {
html.append((new String(b)).toString());
b = new byte[1024];
}
System.out.println(html);
}
} catch (Exception ex) {
throw new SystemException(Common.ERROR_OTHER, ex.getMessage());
}
}
catch(Exception ex) {
System.out.println("Exception>>"+ex.getMessage());
}
XML リクエストをサーバーに送信する方法はたくさん試しました。方法の 1 つは、上記のコードのように見えることです。NullException をスローする理由がわかりません。私のコードに何か問題がありますか? 手伝ってくれてありがとう。