使用Facebook Android SDK 3.0上传照片时出现间歇性SSL错误

使用Facebook Android SDK 3.0上传照片时出现间歇性SSL错误,第1张

概述我正在使用FacebookAndroidSDK3.0将照片上传到我的相册.一切正常,但有时第一次上传失败,出现了一些意想不到的SSL错误.请参阅Request.java中的函数toHttpConnection.try{connection=createConnection(url);serializeToUrlConnection(requests,connect

我正在使用Facebook Android SDK 3.0将照片上传到我的相册.一切正常,但有时第一次上传失败,出现了一些意想不到的SSL错误.

请参阅Request.java中的函数tohttpconnection.

try {        connection = createConnection(url);        serializetoUrlConnection(requests, connection);    } catch (IOException e) {        // THIS IS WHERE THE ERROR ORIGINATES FROM!        throw new FacebookException("Could not construct request body", e);    } catch (JsONException e) {        throw new FacebookException("Could not construct request body", e);    }

在Eclipse中悬停e会显示以下信息:

javax.net.ssl.SSLException:写入错误:ssl = 0x4f033008:系统调用期间的I / O错误,管道损坏
javax.net.ssl.SSLException:写入错误:ssl = 0x4f033008:系统调用期间的I / O错误,管道损坏
写入错误:ssl = 0x4f033008:系统调用期间的I / O错误,管道损坏
[1277468208,0,1279934152,48,1280860304,26,1280860480,58,1280859576,11,1280859696,4,1277492792,1,1280859640,7,1280233152,169,1280233264,36,1280230744,6,1280236632,0,1280236576 ,0,1280238568,6,1280238512,2,1278731744,21,1279835640,23,1278097880,2,1279841920,28,1279843376,2,1277300032,6]
空值

这是SDK中的错误吗?有没有人遇到过这个?更重要的是,我该如何解决?

解决方法:

我几乎准备好接受我之前(删除)的答案,直到我看到这篇文章:http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/

我决定试一试,它似乎工作!这是我的代码:

for (Bitmap b : bitmaps) {    // ID is just a string    String response = executeUpload(b, ID);    // do something with the response}private String executeUpload(Bitmap b, String ID) throws MalformedURLException, IOException {    ByteArrayOutputStream baos = new ByteArrayOutputStream();    b.compress(CompressFormat.PNG, 100, baos);    byte[] data = baos.toByteArray();    httpPost postRequest = new httpPost("https://graph.facebook.com/me/photos");    httpParams params = new BasichttpParams();    httpconnectionParams.setConnectionTimeout(params, 3000);    httpClIEnt httpClIEnt = new DefaulthttpClIEnt();    httpClIEnt.sethttpRequestRetryHandler(new DefaulthttpRequestRetryHandler(2, true));    ByteArrayBody bab = new ByteArrayBody(data, ID + ".png");    multipartentity reqEntity = new multipartentity(httpMultipartMode.broWSER_COMPATIBLE);    reqEntity.addPart("access_token", new StringBody(activeFacebookAccesstoken));    reqEntity.addPart("message", new StringBody(""));    reqEntity.addPart("picture", bab);    postRequest.setEntity(reqEntity);    httpResponse response = httpClIEnt.execute(postRequest);    BufferedReader reader = new BufferedReader(new inputStreamReader(response.getEntity().getContent(), "UTF-8"));    String s;    StringBuilder builder = new StringBuilder();    while ((s = reader.readline()) != null) {        builder = builder.append(s);    }    return builder.toString();}

如上面的链接所述,您必须安装最新的httpClIEnt(位于http://hc.apache.org/downloads.cgi).

另一个需要注意的重要事项是,Facebook支持任一维度的最大图像大小为720像素.在我的代码中,我在进行上传之前将位图缩放到该大小限制内,这极大地提高了性能.

总结

以上是内存溢出为你收集整理的使用Facebook Android SDK 3.0上传照片时出现间歇性SSL错误全部内容,希望文章能够帮你解决使用Facebook Android SDK 3.0上传照片时出现间歇性SSL错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1106375.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存