脚本宝典收集整理的这篇文章主要介绍了php – 如何让Android应用程序通过互联网与Web服务器通信?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我也熟悉PHP和虚拟主机.
我想做的是,让一个AndROId应用程序通过互联网将图像发送到服务器,并使服务器返回一个处理过的图像.我不知道我是怎么做到的.
你能否告诉我如何实现这个目标或者我应该研究哪些主题?另外,我可以使用哪些脚本在Web服务器上进行处理?特别是,我可以使用PHP还是Java?
谢谢!
For Image Uploading ///Method Communicate wITh webservice an return Yes if Image uploaded else NO String executeMultipartPost(Bitmap bm,String image_name) { String resp = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bm.COMPress(ComPRessFormat.JPEG,75,bos); byte[] data = bos.toByteArray(); HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost("domain.com/upload_image.PHP"); ByteArrayBody bab = new ByteArrayBody(data,image_name); multipartentity reqEntity = new multipartentity(HttpMultipartMode.brOWSER_COMPATIBLE); reqEntity.addPart("uploaded",bab); reqEntity.addPart("photoCaption",new StringBody("sfsDFsdf")); postRequest.setEntity(reqEntity); HttpResponse response = httpClient.execute(postRequest); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),"UTF-8")); String sResponse; StringBuilder s = new StringBuilder(); while ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); } resp=s.toString(); } catch (Exception e) { // handle exception here LOG.e(e.getClass().getName(),e.getMessage()); } return resp; } //PHP Code <?PHP $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)) { echo "yes"; } else { echo "no"; } ?>
以上是脚本宝典为你收集整理的php – 如何让Android应用程序通过互联网与Web服务器通信?全部内容,希望文章能够帮你解决php – 如何让Android应用程序通过互联网与Web服务器通信?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。