Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android将base64编码图像上载到WCF服务_Android_Wcf_Base64 - Fatal编程技术网

从android将base64编码图像上载到WCF服务

从android将base64编码图像上载到WCF服务,android,wcf,base64,Android,Wcf,Base64,我有一个Android程序,可以将图像上传到WCF服务。WCF服务接受带有图像名称、文件夹名称和图像base64编码的JSON对象 我使用fiddler测试该服务,我对来自在线服务的图像进行编码并将其放入对象中。然后编写一个POST请求;然后WCF服务成功上传图像 但是,当我使用Android HTTP客户端并执行相同的操作时,WCF会接受请求,但我无法识别图像 以下是我的Android代码: try { HttpPost httpPost=new HttpPost(this.remot

我有一个Android程序,可以将图像上传到WCF服务。WCF服务接受带有图像名称、文件夹名称和图像base64编码的JSON对象

我使用fiddler测试该服务,我对来自在线服务的图像进行编码并将其放入对象中。然后编写一个POST请求;然后WCF服务成功上传图像

但是,当我使用Android HTTP客户端并执行相同的操作时,WCF会接受请求,但我无法识别图像

以下是我的Android代码:

try {
    HttpPost httpPost=new HttpPost(this.remoteBasePath);
    JSONObject obj = new JSONObject();
    obj.put(FILE_NAME, fileName);
    obj.put(FILE_STREAM,fileStream);
    obj.put(FOLDER_NAME, remoteFolder);
    httpPost.setHeader("Content-type", "application/json; charset=utf-8");
    httpPost.setEntity(new StringEntity(obj.toString()));
    httpPost.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    httpResponse=httpClient.execute(httpPost);
    if(httpResponse!=null){
        TLLog.d(TAG,"StatusCode : "+ httpResponse.getStatusLine().getStatusCode());
        if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {                               
            InputStream instream = httpResponse.getEntity().getContent();
            BufferedReader r = new BufferedReader(
            new InputStreamReader(instream));
            StringBuilder total = new StringBuilder();
            String line;
            while ((line = r.readLine()) != null) {
                total.append(line);
            }
            instream.close();
            String result = total.toString();
            TLLog.d(TAG,"Image posting result : "+ result);
            return true;
        }
    }
} catch (ClientProtocolException e) {
    TLLog.e(TAG, e.getStackTrace().toString());
} catch (IOException e) {
    TLLog.e(TAG, e.getStackTrace().toString());
} catch (JSONException e) {
    e.printStackTrace();
}

我不明白这个问题。

嗨,伙计们,我终于解决了这个问题。 问题是编码,所以我使用从internet下载的类。我使用以下方法进行编码

public static String encodeTobase64(Bitmap image) throws IOException
{
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();  
    image.compress(Bitmap.CompressFormat.JPEG, 50, outputStream);
    byte[] bs = outputStream.toByteArray();
    String imageEncoded=Base64.encodeBytes(bs);
    return imageEncoded;
}

并使用返回值作为文件流。所以我的问题就解决了。

如果问题只是图像,我想当您将
fileStream
放入JSON对象时,它已经错了。谢谢您的回复。现在我正在解决这个问题。