C# – Connection: keep-alive Header is Not Being Sent During HttpWebRequest

I’ve had the same issue: The Connection: Keep-Alive header is not sent except the first request, and the server I accessed won’t give me the correct response if it is missing. So, here are my workarounds to this issue: First is set the ProtocolVersion property of HttpWebRequest instance to HttpVersion.Version10. Except the http command will … Read more

Simple HTTP/TCP health check for MongoDB

I’ve created a simple health check for mongodb, it uses the mongo client to send a simple query request (eg. db.stats()) to the server. $ mongo 192.168.5.51:30000/test MongoDB shell version: 3.2.3 connecting to: 192.168.5.51:30000/test mongos> db.stats() { “raw” : { “set1/192.168.5.52:27000,192.168.5.53:27000” : { “db” : “test”, “collections” : 8, “objects” : 50, “avgObjSize” : 73.12, … Read more

Really logging the POST request body (instead of “-“) with nginx

Nginx doesn’t parse the client request body unless it really needs to, so it usually does not fill the $request_body variable. The exceptions are when: it sends the request to a proxy, or a fastcgi server. So you really need to either add the proxy_pass or fastcgi_pass directives to your block. The easiest way is … Read more

In golang, how to determine the final URL after a series of redirects?

package main import ( “fmt” “log” “net/http” ) func main() { resp, err := http.Get(“http://stackoverflow.com/q/16784419/727643”) if err != nil { log.Fatalf(“http.Get => %v”, err.Error()) } // Your magic function. The Request in the Response is the last URL the // client tried to access. finalURL := resp.Request.URL.String() fmt.Printf(“The URL you ended up at is: %v\n”, … Read more

What are the advantages of using a GET request over a POST request?

I generally set up the question as thus: Does anything important change after the request? (Logging and the like notwithstanding). If it does, it should be a POST request, if it doesn’t, it should be a GET request. I’m glad that you call POST requests “slightly” more secure, because that’s pretty much what they are; … Read more