图片BASE64 通过POST提交后,似乎字符被修改了。 post提交不会修改流数据的,你可以把发之前和发之后的数据拿出来自己比较一下,应该是哪个地方处理有问题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 发之前和发之后的byte[]确实不一样。所以才换衣室POST提交造成的啊。 我发现在POST前BASE64有+,POST后+变成了空格. 不应该吧,我最近的项目就是上传图片的base64编码,post的,一直很正常啊 用urlencode吧怎么加?以下是我的POST方法:public static String Post(String strUrl, HashMap hmParameter,String htmlCode) throws Exception { URL u = null; HttpURLConnection con = null; String postData = ""; for (Iterator itr = hmParameter.keySet().iterator(); itr.hasNext();) { String key = (String) itr.next(); String value = (String) hmParameter.get(key); if (postData == "") { postData = key + "=" + value; } else { postData += "&" + key + "=" + value; } } try { u = new URL(strUrl); con = (HttpURLConnection) u.openConnection(); con.setRequestMethod("POST"); con.setDoOutput(true); con.setDoInput(true); con.setConnectTimeout(5 * 1000); con.setUseCaches(false); con.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); OutputStreamWriter osw = new OutputStreamWriter(con .getOutputStream(),htmlCode); osw.write(postData); osw.flush(); osw.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.disconnect(); } } StringBuffer buffer = new StringBuffer(); try { BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())); String temp; while ((temp = br.readLine()) != null) { buffer.append(temp); buffer.append("\n"); } } catch (Exception e) { e.printStackTrace(); } return buffer.toString(); } 把空格再替换成加号不就行了 http://blog.csdn.net/wang0928007/article/details/7429568 有人告诉我是字符集的问题,但是我的JSP,JAVA都是用的UTF-8 请教一个JavaFX App部署问题 关于Random() 和net.mindView.util.Print 使用WindowAdapter,始终有错。 Container和JPanel有什么区别 正则表达式的应用 求去掉-的java代码? 我是菜鸟,想学JAVA,不知道怎么开始,望高手指点谢谢 找不到自己的包? intern()的问题? 紧急求救!1000分大奉送!!!! 小白求助!关于包的引入? 新手求组!!
发之前和发之后的byte[]确实不一样。所以才换衣室POST提交造成的啊。
public static String Post(String strUrl, HashMap hmParameter,String htmlCode) throws Exception {
URL u = null;
HttpURLConnection con = null;
String postData = "";
for (Iterator itr = hmParameter.keySet().iterator(); itr.hasNext();) {
String key = (String) itr.next();
String value = (String) hmParameter.get(key);
if (postData == "") {
postData = key + "=" + value;
} else {
postData += "&" + key + "=" + value;
}
}
try {
u = new URL(strUrl);
con = (HttpURLConnection) u.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
con.setConnectTimeout(5 * 1000);
con.setUseCaches(false);
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
OutputStreamWriter osw = new OutputStreamWriter(con .getOutputStream(),htmlCode);
osw.write(postData);
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (con != null) {
con.disconnect();
}
}
StringBuffer buffer = new StringBuffer();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String temp;
while ((temp = br.readLine()) != null) {
buffer.append(temp);
buffer.append("\n");
} } catch (Exception e) {
e.printStackTrace();
}
return buffer.toString();
}