http download file name

You need to append the HTTP response header “Content-Disposition” Response.AppendHeader(“content-disposition”, “attachment; filename=\”” + fileName +”\””);

HTTP 400 (bad request) for logical error, not malformed request syntax

Status 422 (RFC 4918, Section 11.2) comes to mind: The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was … Read more

Make a URL-encoded POST request using `http.NewRequest(…)`

URL-encoded payload must be provided on the body parameter of the http.NewRequest(method, urlStr string, body io.Reader) method, as a type that implements io.Reader interface. Based on the sample code: package main import ( “fmt” “net/http” “net/url” “strconv” “strings” ) func main() { apiUrl := “https://api.com” resource := “/user/” data := url.Values{} data.Set(“name”, “foo”) data.Set(“surname”, “bar”) … Read more

How to define the basic HTTP authentication using cURL correctly?

curl -u username:password http:// curl -u username http:// From the documentation page: -u, –user <user:password> Specify the user name and password to use for server authentication. Overrides -n, –netrc and –netrc-optional. If you simply specify the user name, curl will prompt for a password. The user name and passwords are split up on the first … Read more