eeewwwnnn 2012-10-17 10:15
浏览 511
已采纳

关于unity3d与java客户端通信传图片的问题

最近项目中用到了unity,需要在unity中截图,并通过webservices将截图信息传递到java服务器端上。但是在java服务器端上出现了问题,我查了资料不知道如何解决,求指点!!

 

这个是我在unity中写的截取图像的代码,图片信息需要通过WWWFORM上传到java服务器端上

public byte[] shot()
    {
        int width = Screen.width;
        int height = Screen.height;
        Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
        byte[] bytes = tex.EncodeToPNG();
        return bytes;
    }

    public void getScreenshotByUrl(string data) {
        StartCoroutine(GetScreenshot(data));
    }

    public IEnumerator GetScreenshot(string data)
    {

        byte[] result = shot();
        IDictionary jsonDic = (IDictionary)Json.Deserialize(data);
        string normalUrl = (string)jsonDic["normalUrl"];        
       
        string time = string.Format("{0:yyyyMMddHHmmss}", DateTime.Now);
       
        //创建一个Web表单
        WWWForm form = new WWWForm();
        form.AddField("arg0", time);
        form.AddBinaryData("arg1", result);


        WWW www = new WWW(normalUrl.ToString(), form);
        yield return www;

        if (www.error != null)
            print(www.error);
        else
            print("Finished Uploading Screenshot");

    }

 这个是在JAVA中的服务器端的webservices代码

  
    @Override
    public int insertPic(String name,byte[] content) throws Exception {
        
        System.out.println(content);
        System.out.println(name);
        return (Integer) null;
    }

 这个是后台报的错误

2012-10-17 10:13:05 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
警告: Interceptor for {http://web.webservice.firems.suresource.com/}LocationWebserviceImplService has thrown exception, unwinding now
org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader.
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:237)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:60)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:128)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,1]
Message: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:594)
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.nextTag(XMLStreamReaderImpl.java:1235)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:138)
    ... 27 more
  • 写回答

5条回答 默认 最新

  • iteye_5246 2012-10-17 11:54
    关注

    C# 有读取文件流 的方法吧。只需要u3d脚步里面获取默认图片的位置,那么随便百度一个c# 上传文件。模拟post提交http请求。。。那么这样请求java服务器上传图片的方法。。
    c# 只是模拟一次http请求传参而已

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 maccms影视模板 制作影视网站失败 求
  • ¥15 stm32按键设置闹钟数进退位不正常
  • ¥15 三电平逆变器中点电位平衡问题
  • ¥20 这怎么写啊 java课设
  • ¥15 用C语言完成一个复杂的游戏
  • ¥15 如何批量更改很多个文件夹里的文件名中包含文件夹名?
  • ¥50 MTK手机模拟HID鼠标出现卡顿
  • ¥20 求下下面这个数据结构代码
  • ¥20 前端 二进制文件流图片转化异常
  • ¥15 github上的这个C语言项目如何跑起来