我基本上是从Android上传图像并上传到PHP服务器,但在这里我没有得到任何与此代码或图像上传的连接.
我收到了这个错误.
Error in http connection java.net.UnknownHostException: host name
但据我所知,我给了正确的连接和PHP文件也在正确的域.
看看我的代码:
UploadImage.java
public class UploadImage extends Activity {
InputStream inputStream;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.icon);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,90,stream); //compress to which format you want.
byte [] byte_arr = stream.toByteArray();
String image_str = Base64.encodeBytes(byte_arr);
ArrayList
}
PHP代码:
有谁知道这个问题?如果有人知道如何从php文件存储在mysql数据库中并获取反之请在这里建议我…
最佳答案
问题很明显……
Error in http connection java.net.UnknownHostException: host name
表示HttpPost无法使用您提供的主机名建立连接 – 因为您提供的主机名是未知的.
如果您从此行获取主机名:
HttpPost httppost = new HttpPost("http://server.com/uploadimage/uploadimage.php");
并将其放在同一设备上的浏览器中会发生什么……我建议您收到错误消息,说无法连接到主机.如果这样可行,那么我建议您检查以下行是否在您的清单中:
如果您使用JPEG,还要确保PHP文件包含以下标题:
header('Content-Type: image/jpg');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。