static public String post( String ip_postData, String ip_pageUrl)
{
try
{
String strResult = "";
URL url = new URL(ip_pageUrl);
URLConnection con = url.openConnection(); //from secure site
if(con instanceof com.sun.net.ssl.HttpsURLConnection){
((com.sun.net.ssl.HttpsURLConnection)con).setSSLSocketFactory
(SSLSocketFactory)SSLSocketFactory.getDefault());
}
con.setDoOutput(true);
con.setDoInput(true);
// Set request headers for content type and length
con.setRequestProperty(
"Content-type",
"application/x-www-form-urlencoded");
con.setRequestProperty(
"Content-length",
String.valueOf(ip_postData.length()));
// Issue the POST request
OutputStream outStream = con.getOutputStream();
outStream.write(ip_postData.getBytes());
outStream.flush();
// Read the response
PayDollar PayGate Integration Guide (v3.14) Page 32
InputStream inStream = con.getInputStream();
while (true)
{
int c = inStream.read();
if (c == -1)
break;
strResult = strResult + String.valueOf((char)c);
}
inStream.close();
outStream.close();
return strResult;
}
catch (Exception e)
{
System.out.print(e.toString());
return null;
}
}
{
try
{
String strResult = "";
URL url = new URL(ip_pageUrl);
URLConnection con = url.openConnection(); //from secure site
if(con instanceof com.sun.net.ssl.HttpsURLConnection){
((com.sun.net.ssl.HttpsURLConnection)con).setSSLSocketFactory
(SSLSocketFactory)SSLSocketFactory.getDefault());
}
con.setDoOutput(true);
con.setDoInput(true);
// Set request headers for content type and length
con.setRequestProperty(
"Content-type",
"application/x-www-form-urlencoded");
con.setRequestProperty(
"Content-length",
String.valueOf(ip_postData.length()));
// Issue the POST request
OutputStream outStream = con.getOutputStream();
outStream.write(ip_postData.getBytes());
outStream.flush();
// Read the response
PayDollar PayGate Integration Guide (v3.14) Page 32
InputStream inStream = con.getInputStream();
while (true)
{
int c = inStream.read();
if (c == -1)
break;
strResult = strResult + String.valueOf((char)c);
}
inStream.close();
outStream.close();
return strResult;
}
catch (Exception e)
{
System.out.print(e.toString());
return null;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货