【发布时间】:2015-11-10 12:11:33
【问题描述】:
这是重要的代码:
elif msgheader.startswith( 'POST' ):
print "The POST msg:\n", msgheader
这是回应:
The POST msg:
POST / HTTP/1.1
Host: 192.168.1.102:63166
Connection: keep-alive
Content-Length: 12
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://192.168.1.102:63166
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://192.168.1.102:63166/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
comment=test
现在我的问题是如何打印出响应的各个行,例如评论字段。我尝试使用此代码,但出现错误:
print['comment']
Exception (with type 'exceptions.TypeError'): string indices must be integers, not str
【问题讨论】: