本文介绍了虽然错误使用Base64发送JSON数据到服务器的连接codeD映像串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的code我发送JSON数据像这样
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imgbmp.compress(Bitmap.CompressFormat.PNG, 90, baos);
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeBytes(b);
jsonstr = new JSONStringer().object().key("Text")
.value(msg).key("Files").array().object().key(
"ContentType").value("image/png").key(
"Content").value(encodedImage)
.endObject().endArray().key("AuthToken").value(token)
.endObject();
StringEntity entity = new StringEntity(jsonstr.toString());
entity.setContentType("application/json;charset=UTF-8");
entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json;charset=UTF-8"));
request.setEntity(entity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse res = httpClient.execute(request);
,我是在执行收到此错误HttpClient的
09-30 11:56:21.571: INFO/Request(22161): org.apache.http.client.methods.HttpPost@468613b0
09-30 11:56:21.586: INFO/JSON ANS(22161): <Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"><Code><Value>Receiver</Value><Subcode><Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</Value></Subcode></Code><Reason><Text xml:lang="en-US">The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. </Text></Reason><Detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true"/><InnerException i:nil="true"/><Message>The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. </Message><StackTrace> at System.Convert.FromBase64String(String s)
09-30 11:56:21.586: INFO/JSON ANS(22161): at Zoodig.Core.WebServices.DataContracts.FileContract.GetStream()
09-30 11:56:21.586: INFO/JSON ANS(22161): at Zoodig.WebServices.Services.AthletesService.PostUpdate(PostUpdateContract data)
09-30 11:56:21.586: INFO/JSON ANS(22161): at SyncInvokePostUpdate(Object , Object[] , Object[] )
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
09-30 11:56:21.586: INFO/JSON ANS(22161): at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><Type>System.FormatException</Type></ExceptionDetail></Detail></Fault>
请如果有人能理解这一点,并告诉我什么here..where发生的事情是,我所做的任何mistakes..and为什么我收到错误的posibilities?
感谢您。
MKJParekh
Thank You.MKJParekh
推荐答案
我得到的答案...
我没有做任何那样的失误
i got the answer...i was not making any kind of mistakes
这是问题org.json
that was problem with org.json
我切换到another..and所有它的工作原理
i switched to another..and all it works
nesting在JSON太深......我应该切换到XML?
这篇关于虽然错误使用Base64发送JSON数据到服务器的连接codeD映像串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!