如何将基础64编码的字符串从android发送到wcf

时间:2013-05-15 04:35:16

标签: android wcf

我编写了编码图像的功能并将其发送到wcf。嗯不使用查询字符串参数。嗯使用URL传递参数。这是我的Android代码,这很好。

public JSONUpdate(String jobNumber, String documentType,
        String documentFilePath, String DocumentFileName,
        String encodedImage, String url) {

    this.url = url + jobNumber.trim() + "/" + documentType.trim() + "/"
            + documentFilePath.trim().replace("/", "___") + "/"
            + DocumentFileName.trim() + "/" + encodedImage;
}



 public boolean updateService() {
    boolean result = false;
    HttpClient httpClient = new DefaultHttpClient();
    try {
        HttpPost httpPost = new HttpPost(this.url);
        try {
            HttpResponse httpResponse = httpClient.execute(httpPost);
            if (httpResponse != null) {
                if (httpResponse.getStatusLine().getStatusCode() == 200)
                    result = true;
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (Exception ex) {
        String p = ex.getLocalizedMessage();
        String y = ex.getMessage();
    }
    if (!result) {

    }
    return result;
}

在我的WCF实现中也可以正常工作,除非我包含编码的字符串参数,它会抛出一个错误,因为编码的字符串包含'+'和'\'。所以URL破了。这是我的服务WCF代码

    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,
    UriTemplate = "attachment/{jobNumber}/{documentType}/{documentFilePath}/{DocumentFileName}/{encodedImage}",
    BodyStyle = WebMessageBodyStyle.Bare)]
    public bool InsertAttachment(String jobNumber, String documentType,
        String documentFilePath, String documentFileName,
         String encodedImage = null)
    {
        //implementation was written
    }

如何安全地将编码的64位字符串作为带有+和\的参数传递?我没有太多的经验。如果有人能给我一个建议,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

尝试自API 8以来可用的Android Base64实现。

Base64.encodeToString(youtString.getBytes(...), Base64.NO_WRAP + Base64.URL_SAFE);