【发布时间】:2014-10-15 09:13:01
【问题描述】:
在 Grails Web 应用程序中,我正在尝试使用 REST API 将细节(指纹)字节数组从小程序发布到服务器。
这就是我尝试的目的
private String post(String purl,String customerId, byte[] regMin1,byte[] regMin2) throws Exception {
StringBuilder parameters = new StringBuilder();
parameters.append("customerId=");
parameters.append(customerId);
parameters.append("®Min1=");
parameters.append(URLEncoder.encode(new String(regMin1),"UTF-8"));
parameters.append("®Min2=");
parameters.append(URLEncoder.encode(new String(regMin2),"UTF-8"));
URL url = new URL(purl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length",Integer.toString(parameters.toString().getBytes().length));
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(parameters.toString());
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
StringBuilder builder = new StringBuilder();
String aux = "";
while ((aux = in.readLine()) != null) {
builder.append(aux);
}
in.close();
connection.disconnect();
return builder.toString();
}
我可以成功发布 regMin1、regMin2 但指纹验证总是失败。我怀疑,我是否正确发布。
【问题讨论】:
-
你为什么不用apache的
HttpClient?有了它,您可以组装一个没有这种复杂性的 POST 请求 -
@injecteer 好的,我刚开始。谢谢。
-
@Viswa 你能发布你的 grails 代码吗?我想看看你是如何从那里获取数据的。
-
@Ramsharan 感谢您的关注.. 我明白了..
标签: java grails applet http-post fingerprint