我已经尝试了StackOverflow上的每一个例子,接收端总是有一个空的有效负载。
我排除了接收方,因为能够做到这一点:
curl-XPOST'http://supersecreturl/mypost“-d”[{“我向里奇发誓”:“这个json是100%有效的”},{“我甚至可以”:“复制并粘贴到一个curl-POST请求中,并在远程端完美地接收它”}]
求求你帮帮我,我快疯了。。
/// Here is approximately my code - had to remove the valid url and the JSON content
func PutArticlesJSON(c appengine.Context, articles []*Articlez) (*http.Response){
url := "http://mysecreturl/mypost"
client := urlfetch.Client(c)
jsonarts, _ := json.Marshal(articles)
c.Debugf(" --- What do we have - %v", string(jsonarts)) /// the appengine log shows exactly valid json at this point, such as:
/*
[{"i sware to ritchie":"this json is 100 percent valid"},{"i can even":"copy and paste it into a curl POST request and receive it flawless on the remote side"}]
*/
// tried this way too....
//req, err := http.NewRequest("POST", url, strings.NewReader(string(jsonarts)))
//
req, err := http.NewRequest("POST", url, bytes.NewBuffer(string(jsonStr))) /// on the receiving side, the payload is completely empty no matter what I try
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return resp
}
#!/usr/bin/env python
#
from flask import Flask
from flask import request
import urllib
import json
app = Flask(__name__)
@app.route('/mypost', methods = ['GET','POST'])
def esput():
datapack = request.form
datastream = request.stream
with open("/tmp/log", "a") as myf:
myf.write(str(datastream))
myf.write(str(datapack))
myf.write("\n")
return "all good"
if __name__ == '__main__':
app.run(threaded=True,host='0.0.0.0',port='333',debug=False)