【发布时间】:2014-07-16 13:51:40
【问题描述】:
我的要求是使用 facebook 登录,登录后,facebook 信息将是我的应用程序配置文件信息,但是当我尝试使用 facebook 配置文件 pic url 保存我的配置文件时,使用 FileBody 的封面页面图像 url 它给了我文件未找到异常,但个人资料图片 url 和封面页 url 在浏览器中可以正常工作并显示图像。
谁能帮我摆脱困境。
public String[] saveProfile(Context context, String bannerPath, String profilePicPath, String userName)
{
String str_response = "";
String[] arryResponse = new String[2];
mContext = context;
Log.d(TAG, " -- profilePicPath -- " + profilePicPath);
Log.d(TAG, " -- bannerPath -- " + bannerPath);
if (isNetworkConnected())
{
HttpClient httpclient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 10000);
HttpPost httppost = new HttpPost(baseUrl + "user/edituserprofile/");
try
{
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
if (profilePicPath.length() > 0)
{
profilePicPath = profilePicPath.replace("http", "https").toString().trim();
File F = new File(profilePicPath);
FileBody fb = new FileBody(F);
reqEntity.addPart("vProfilePicture", fb);
}
if (bannerPath.length() > 0)
{
bannerPath = bannerPath.replace("http", "https").toString().trim();
File F = new File(bannerPath.replace("http", "https"));
FileBody fb = new FileBody(F);
reqEntity.addPart("vCoverPicture", fb);
}
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String x_api_key = (sharedPreferences.getString(ConstantCode.X_API_KEY, ""));
reqEntity.addPart("vUserName", new StringBody(fullName));
String userId = sharedPreferences.getString(ConstantCode.USER_ID, "");
String accessToken = sharedPreferences.getString(ConstantCode.ACCESS_TOKEN, "");
httppost.addHeader("X_API_KEY", x_api_key);
httppost.addHeader("accesstoken", accessToken);
httppost.addHeader("iUserID", userId);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
str_response = EntityUtils.toString(response.getEntity());
Log.e(TAG, " Edit Profile response " + str_response);
if (!str_response.equals(""))
{
try
{
JSONObject obj = new JSONObject(str_response);
arryResponse[0] = obj.getString("STATUS");
arryResponse[1] = obj.getString("MESSAGE");
} catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (ClientProtocolException e)
{
Log.e(TAG, " Edit Profile ClientProtocolException " + e.toString());
} catch (IOException e)
{
Log.e(TAG, " Edit Profile IOException " + e.toString());
}
}
;
return arryResponse;
}
【问题讨论】:
-
发布Logcat及相关代码。这么难理解吗?
-
请原谅投反对票的人,如果您不知道答案,请不要碰问题,请留下。如果您对此有所了解,请不要通过投票来展示您的伟大,请给出答案并证明您的知识。
-
@Marius 我把我的代码,可以帮助我吗?
-
也包括Logcat,并高亮出现异常的部分。我对你投了反对票,因为问题几乎没有显示任何研究,也没有足够的细节来识别问题。如果你解决了这些问题,我将删除我的反对票。
标签: android exception http-post