1

全部

我从 Flash 客户端 (AS3) 向 RESTFull 服务发送一个 http 请求。服务器端响应 json 或 xml 数据取决于 http 标头中的“接受”参数。但是,即使我在客户端将“接受”设置为“应用程序/json”,我也总是接受 xml 格式的数据。使用wireshark,我发现http标头中有双重'Accept'参数。有人可以告诉我为什么吗?和/或如何摆脱这种情况。

POST /psplatform/rest/szdata/all HTTP/1.1
Host: 203.175.156.88:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-type: application/json
Accept: application/json
Content-length: 8





public function reload():void{
            data = new Object();
            new URLLoader(createJSONURLRequest("http://203.175.156.88:8080/psplatform/rest/szdata/all")).addEventListener(Event.COMPLETE, loaderCompleteHandler); 
        }

        private function createJSONURLRequest(url:String):URLRequest{
            var urlRequest:URLRequest = new URLRequest(url);
            urlRequest.method = URLRequestMethod.POST;
            urlRequest.contentType = "application/json";
            //var urlVariables:URLVariables = new URLVariables("{}");
            urlRequest.data = "{name:0}";
            urlRequest.requestHeaders.push(new URLRequestHeader("Accept", "application/json"));
            return urlRequest;
        }
4

0 回答 0