3

画像をエンコードして 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 ビット文字列をパラメーターとして安全に渡す方法は? 私はそれについてあまり経験がありません。誰かが私に提案を与えることができれば、私は感謝します.

4

1 に答える 1

1

API 8 以降で利用可能なAndroid Base64実装を試してください。

Base64.encodeToString(youtString.getBytes(...), Base64.NO_WRAP + Base64.URL_SAFE);
于 2013-05-15T04:39:44.337 に答える