&安培;转换成&什么时候调用$ _POST请求?

时间:2013-11-25 08:58:06

标签: php android apache post

我们正在开发一个包含2个模块的应用程序。

  1. Android应用程序。
  2. PHP应用程序 PHP后端应用程序在带有Centos Server的Apache服务器上运行。 Android应用程序基本上点击图像,与gps坐标等表格信息一起发送到服务器。
  3. 现在,在服务器上创建映像文件时出现问题。当Android应用程序调用网址'&'时字符被&取代amp;有时甚至是&安培;&安培;放大器;在某些情况下,这个问题会重演。一旦发生这种转换,就无法正确创建图像文件。

    如何解决?

    同样的代码在过去的一年里工作正常,这个问题从上个月才开始出现......

    以下是在服务器端保存图像的代码:

    foreach($_POST as $key => $value) { 
        $_POST[$x] = $value;
    }
    
    $base=$_REQUEST['image'];
    $nm=$_REQUEST['name'];
    $binary=base64_decode($base);
    
    
    if(file_exists("uploaded_images/".$nm.".jpg")) {
    
    unlink("uploaded_images/".$nm.".jpg");
    }
    
    header('Content-Type: bitmap; charset=utf-8');
    $str="uploaded_images/".$nm.".jpg";
    $file = fopen($str, 'wb');
    fwrite($file, $binary);
    fclose($file);
    chmod($file,0777);
    $ok=1;
    echo $ok;
    

    以下是未正确保存图像时遇到的错误日志。 PHP注意:未定义的索引:/var/www/html/cbd/def/filesubmitnew.php中的名称 注意:filesubmitnew.php是上述代码的文件名。

    在Android应用程序中,这是如何调用URL:

    创建图片:

    if(buttontext.equals("Img1"))   {
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        v.setImageBitmap(bitmap);
        buttontext="";
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 20, stream);
        byte [] byte_arr = stream.toByteArray();
        String str1 = Base64.encodeBytes(byte_arr);
        System.out.println(""+str1);
        if(feuser.equals("offline_access")){
        System.out.println("++==--SD CARD");
        File externalStorage = Environment.getExternalStorageDirectory();
        File folder = new File(externalStorage.getAbsolutePath() +mainFolder + caseId);
        if (!folder.exists()) {
            folder.mkdir();
        }
        File pictureFile = new File(externalStorage.getAbsolutePath()+mainFolder+caseId, "1.jpg");
        System.out.println(pictureFile);
        pictureFile.createNewFile();
        FileOutputStream fOut = new FileOutputStream(pictureFile);
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(str1);
        myOutWriter.close();
        fOut.close();
        Toast.makeText(getBaseContext(),"Done writing SD "+pictureFile,Toast.LENGTH_SHORT).show();
    }
    else    {
    
        Intent i = new Intent ("com.keyboardlabs.newbankge.CameraUploadService");
        try {
            i.putExtra("imageparams", str1);
            i.putExtra("ref_id", caseId);
            i.putExtra("imageId", "1");
            i.putExtra("CaseType",caseType);
        } 
        catch (Exception e) {
            e.printStackTrace();
        }
        getApplicationContext().startService(i);
    }
    

    以下是camerauploadservice

    protected void onHandleIntent(Intent arg0) {
    
        String imageDataBase64encoded =  arg0.getStringExtra("imageparams");
    String caseID = arg0.getStringExtra("ref_id");
    String imageId = arg0.getStringExtra("imageId");
    String caseType =arg0.getStringExtra("CaseType");
    System.out.println("image_ref="+caseID+"iamgeID="+imageId+"caseType="+caseType+" URL="+URL);
    
    callWebService(imageDataBase64encoded,caseID,imageId,caseType);
    }
    
    public void callWebService(String imageData,String refId,String imageId,String caseType){  
    
        HttpClient httpclient = null;
    
    ArrayList<NameValuePair> nameValuePairs = new  ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("image",imageData));
    nameValuePairs.add(new BasicNameValuePair("ref_id",refId));
    nameValuePairs.add(new BasicNameValuePair("imageId",imageId));
    nameValuePairs.add(new BasicNameValuePair("CaseType",caseType));
    try{
        httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(URL);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        String the_string_response = convertResponseToString(response);
        System.out.println( "Response= " + the_string_response);
    }catch(Exception e){
        System.out.println( "0" + e.getMessage());
        System.out.println("Error in http connection "+e.toString());
    }
    httpclient.getConnectionManager().shutdown();  
    }
    

0 个答案:

没有答案