这是我的功能:
public String uploadImage(URL image,String message) throws Exception{
HashMap<String,String> paramArgs=new HashMap<String,String>();
paramArgs.put("fbImgPostURL","https://graph.facebook.com/me/photos");
paramArgs.put("accessToken",accessGrant.getKey());
paramArgs.put("imageURL",image.toString());
paramArgs.put("message",message);
return HttpPictureUpload.uploadImageViaHttpPost(paramArgs);
}
当我从intelliJ调试器调试它时,奇怪的是在行
paramArgs.put("accessToken",accessGrant.getKey());
显然,关键是accessToken
。但调试器显示如下:
access_token
=CAACKan8suD0BAKUZAyxLinmXw2PZAkmkhIhVZCojG1sE2QsW60CfQjZAJWyMbqc1Lxy1JmVmSyAU4eHOGSkHhqJSQE6tcORuXAkyFbok7WGyysgJYZC6QF6KZBPRwDwbPCE6JUJgKIGyXzZCfzVgnjHHuoZBLZBt2xXgZD
很明显,问题是我设置了一个不同的键名,但是在哈希映射中,设置了一个不同的键名,它实际上被传递给
HttpPictureUpload.uploadImageViaHttpPost(paramArgs);
这里的任何人都可以猜到发生了什么?
编辑:
这是我的uploadImageViaHttpPost()
功能:
public static String uploadImageViaHttpPost(HashMap<String,String> keyParams){
String in="Image Uploaded Successfully!!";
try {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(keyParams.get("fbImgPostURL"));
//Add any parameter if u want to send it with Post req.
method.addParameter("accessToken", keyParams.get("accessToken"));
method.addParameter("url",keyParams.get("imageURL"));
method.addParameter("message",keyParams.get("message"));
int statusCode = client.executeMethod(method);
if (statusCode != -1) {
in = method.getResponseBodyAsString();
}
System.out.println(in);
} catch (Exception e) {
e.printStackTrace();
}
return in;
}