Skip to content

Instantly share code, notes, and snippets.

@redbo
Last active April 27, 2016 08:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save redbo/7d65b87b4d75f2084d11 to your computer and use it in GitHub Desktop.
Save redbo/7d65b87b4d75f2084d11 to your computer and use it in GitHub Desktop.
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()
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)
}
* 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