2008-09-29 13 views
0

私は開発したカスタムPython Webサーバーと通信するFlexアプリケーションを取得しようとしています。Flex HTTPServiceにContent-Lengthヘッダーが含まれていませんか?

FlexでContent-LengthがHTTPヘッダーに含まれていないように見えるため、受信したポストデータを読み取ることができないことに気づいています。 (普通のHTMLから投稿されたときの私のWebサーバーの仕事)

これは既知の問題ですか?任意のアイデアはどのようにコンテンツの長さのヘッダーを設定する?ここで

が送信されている現在のヘッダです:

 
Host: localhost:7070 

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0 

.3 

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 

Accept-Language: en-us,en;q=0.5 

Accept-Encoding: gzip,deflate 

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 

Keep-Alive: 300 

Connection: keep-alive 

答えて

0

私は、これは既知の問題であるとは考えていません。

Content-Lengthは送信されていませんか?ブラウザからHTTPインタラクションのリクエスト側を投稿しました。プロトコルのその側に決してContent-Lengthヘッダーがありません。

4

HTTPServiceのメソッドプロパティをPOSTに設定している限り、これは必須です。これを省略すると、デフォルトでGETになり、パラメータはPOSTデータではなくクエリ文字列の一部として送信されます。

私は、このFlexコードを使用してこのシナリオを設定します。

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application layout="absolute" 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    creationComplete="init()"> 

    <mx:HTTPService id="service" 
     url="http://localhost:8000/" 
     method="POST" 
     resultFormat="text" 
     result="response.htmlText=ResultEvent(event).result.toString()"/> 

    <mx:Text id="response" width="100%" height="100%"/> 

    <mx:Script> 
     <![CDATA[ 
      import mx.rpc.events.ResultEvent; 
      private function init() : void { 
       service.send({ 
        foo: "Fred", 
        bar: "Barney" 
       }); 
      } 
     ]]> 
    </mx:Script> 
</mx:Application> 

そして、このPythonのサーバコード:

#!/usr/bin/env python 

import SimpleHTTPServer, BaseHTTPServer, string 

class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): 
    def do_POST(self): 
     self.send_response(200) 
     self.send_header("Content-type", "text/html") 
     self.end_headers() 
     self.wfile.write("<html><body>") 
     self.wfile.write("<b>METHOD:</b> " + self.command) 

     # Write out Headers 
     header_keys = self.headers.dict.keys() 
     for key in header_keys: 
      self.wfile.write("<br><b>" + key + "</b>: ") 
      self.wfile.write(self.headers.dict[key]) 

     # Write out any POST data 
     if self.headers.dict.has_key("content-length"): 
      content_length = string.atoi(self.headers.dict["content-length"]) 
      raw_post_data = self.rfile.read(content_length) 
      self.wfile.write("<br><b>Post Data:</b> " + raw_post_data) 
     self.wfile.write("</body></html>") 
    def do_GET(self): 
     self.do_POST() 

try: 
    BaseHTTPServer.test(MyHandler, BaseHTTPServer.HTTPServer) 
except KeyboardInterrupt: 
    print 'Exiting...' 

そして、この結果得た:それは動作するはずですので

METHOD: POST 
content-length: 19 
accept-language: en-us,en;q=0.5 
accept-encoding: gzip,deflate 
connection: keep-alive 
keep-alive: 300 
accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
user-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 
accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
host: 10.0.7.61:8000 
content-type: application/x-www-form-urlencoded 
Post Data: bar=Barney&foo=Fred 

を。

0

Bill Dの言うとおり、私たちはサーバーコードでそれらを守っているので、ほぼ確実にPOSTを実行しているわけではなく、確かにContent-Lengthが含まれています。

関連する問題