业务场景:项目中要对用户信息进行实名认证,上传参数有用户姓名,电话,身份证号码,身份证正面图片,反面图片。
对身份证正反面图片进行BASE64编码,然后对整个参数进行加密,处理参数之后整个URL后面的参数有38万多个字节,371K.然后用下面的POST方法进行请求服务器,请问大神,这个请求能否成功?
下面那段代码就是post请求的方法,让我困惑的是在执行
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
这两行代码时,是否就会以这个超长的url去与服务器建立连接?
然后导致连接失败?
求大神指点迷津
public static String sendPostUrl(String url, String param, String charset)
{
PrintWriter out = null;
BufferedReader in = null;
StringBuffer result = new StringBuffer();
try
{
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(
conn.getInputStream(), charset));
String line;
while ((line = in.readLine()) != null)
{
String line;
result.append(line);
}
}
catch (Exception e)
{
e.printStackTrace();
try
{
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
}
catch (IOException ex)
{
}
}
finally
{
try
{
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
}
catch (IOException ex)
{
}
}
return result.toString();
}