-
-
Save cuixin/0239431fe13cc1c632a23d20bf0f541e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pycurl | |
import cStringIO | |
c = pycurl.Curl() | |
c.setopt(pycurl.VERBOSE, 1) | |
dummydata = "HI THIS IS SOME DATA" | |
c.setopt(pycurl.URL, "http://127.0.0.1:9000/noreadbody") | |
c.setopt(pycurl.UPLOAD, 1) | |
c.setopt(pycurl.READFUNCTION, cStringIO.StringIO(dummydata).read) | |
c.setopt(pycurl.INFILESIZE, len(dummydata)) | |
c.setopt(pycurl.HTTPHEADER, ["Expect: 100-continue"]) | |
c.perform() | |
c.setopt(pycurl.URL, "http://127.0.0.1:9000/readbody") | |
c.setopt(pycurl.UPLOAD, 1) | |
c.setopt(pycurl.READFUNCTION, cStringIO.StringIO(dummydata).read) | |
c.setopt(pycurl.INFILESIZE, len(dummydata)) | |
c.setopt(pycurl.HTTPHEADER, ["Expect: 100-continue"]) | |
c.perform() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"io/ioutil" | |
"net/http" | |
) | |
func hello(w http.ResponseWriter, r *http.Request) { | |
if r.URL.Path == "/readbody" { | |
ioutil.ReadAll(r.Body) | |
} | |
io.WriteString(w, "Hello world!") | |
} | |
func main() { | |
http.HandleFunc("/", hello) | |
http.ListenAndServe(":9000", nil) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* About to connect() to 127.0.0.1 port 9000 (#0) | |
* Trying 127.0.0.1... * connected | |
> PUT /noreadbody HTTP/1.1 | |
User-Agent: PycURL/7.22.0 | |
Host: 127.0.0.1:9000 | |
Accept: */* | |
Content-Length: 20 | |
Expect: 100-continue | |
< HTTP/1.1 200 OK | |
< Date: Thu, 02 Jul 2015 20:18:06 GMT | |
< Content-Length: 12 | |
< Content-Type: text/plain; charset=utf-8 | |
< | |
* Connection #0 to host 127.0.0.1 left intact | |
* Re-using existing connection! (#0) with host 127.0.0.1 | |
* Connected to 127.0.0.1 (127.0.0.1) port 9000 (#0) | |
> PUT /readbody HTTP/1.1 | |
User-Agent: PycURL/7.22.0 | |
Host: 127.0.0.1:9000 | |
Accept: */* | |
Content-Length: 20 | |
Expect: 100-continue | |
< HTTP/1.1 400 Bad Request | |
* no chunk, no close, no size. Assume close to signal end | |
< | |
* Closing connection #0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment