我在golang中有字节数组:
cannot use obj_data (type []byte) as type byte in array element
并且想要将这个字节数组设置为json.RawMessage 我认为它会起作用:
pro_soc = socket.socket()
#connect
pro_soc.bind(("127.0.0.1", 8001))
# wait for proxy request
pro_soc.listen(1)
print "listening...."
client_soc, client_address= pro_soc.accept()
# receive proxy message
client_url = client_soc.recv(1024)
#send webpage data to proxy
file_web = open(client_url,"r")
data_web = file_web.read()
print data_web
pro_soc.send(data_web)
#close
file_web.close()
client_soc.close()
pro_soc.close()
但我有错误:
client_soc = socket.socket()
server_soc = socket.socket()
# connect to socket
client_soc.bind(("127.0.0.1", 8000))
# wait for client request
client_soc.listen(1)
print "listening...."
client_soc, client_address= client_soc.accept()
# receive client message
client_url = client_soc.recv(1024)
#send it to server
server_soc.connect(("127.0.0.1", 8001))
server_soc.send(client_url)
web_data = server_soc.recv(1024)
print web_data
new_data = web_data.replace("japan","china")
new_html = open("newHtml.html","w")
new_html.write(new_data)
webbrowser.open_new_tab("newHtml.html")
# close connection and file
client_soc.close()
server_soc.close()
new_html.close()
请帮帮我! =)