Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug:filename of image with wrong charset encoding #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/com/athena/asm/util/SmthCrawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public boolean uploadAttachFile(File file) {

public boolean sendPost(String postUrl, String postTitle,
String postContent, String signature, boolean isEdit) {

List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("title", postTitle));
formparams.add(new BasicNameValuePair("text", postContent));
Expand All @@ -186,7 +186,7 @@ public boolean sendPost(String postUrl, String postTitle,
else {
formparams.add(new BasicNameValuePair("signature", signature));
}

HttpPost httpPost = new HttpPost(postUrl);
UrlEncodedFormEntity entity;
try {
Expand Down Expand Up @@ -333,7 +333,9 @@ public String fetchAttachmentFilename(String url) {
if (s.contains("filename")) {
// how to decode filename from http header:
// http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http
String rawValue = s.substring(s.lastIndexOf("=") + 1);
// 从fiddler抓包来看,返回的filename基本都是gbk编码,所以这里直接写成gbk编码.也有一部分文件名中有EF BF BD内容的,说明服务器返回的内容有问题,这种暂不处理
String unicodeHeaderValue = new String(s.getBytes("iso-8859-1"), "gbk");
String rawValue = unicodeHeaderValue.substring(unicodeHeaderValue.lastIndexOf("=") + 1);
filename = rawValue;
// Log.d("fetchAttachmentFilename", url + filename);
return filename;
Expand Down