title: Not getting Location header from Golang http request
body: <p>I'm trying to port over something I had written in Node, the request looks like this in Node(JS):</p>
  
  <pre><code>function _initialConnection(user, pass, callback) {
    let opts = {
      url: config.loginURL,
      headers: {
        "User-Agent": "niantic"
      }
    };
  
    request.get(opts, (err, resp, body) =&gt; {
      if (err) return callback(err, null);
  
      console.log(resp.headers);
  
      let data;
      try {
        data = JSON.parse(body);
      } catch(err) {
        return callback(err, null);
      }
      return callback(null, user, pass, data);
    });
  }
  
  function _postConnection(user, pass, data, callback) {
    let opts = {
      url: config.loginURL,
      form: {
        'lt': data.lt,
        'execution': data.execution,
        '_eventId': 'submit',
        'username': user,
        'password': pass
      },
      headers: {
        'User-Agent': 'niantic'
      }
    };
  
  
    request.post(opts, (err, resp, body) =&gt; {
      if (err) return callback(err, null);
  
      let parsedBody;
      if (body) {
        try {
          parsedBody = JSON.parse(body)
          if (('errors' in parsedBody) &amp;&amp; parsedBody.errors.length &gt; 0) {
            return callback(
              new Error('Error Logging In: ' + paredBody.errors[0]),
              null
            )
      }
        } catch(err) {
          return callback(err, null);
        }
      }
  
      console.log(resp.headers)
  
      let ticket = resp.headers['location'].split('ticket=')[1];
  
      callback(null, ticket);
    });
  }
  </code></pre>
  
  <p>If I <code>console.log(resp.headers)</code> I can see a location header.</p>
  
  <p>I have tried to recreate this in Go the best way I could which I ended up with:</p>
  
  <pre><code>// Initiate HTTP Client / Cookie JAR
  
  jar, err := cookiejar.New(nil)
  if err != nil {
      return "", fmt.Errorf("Failed to create new cookiejar for client")
  }
  newClient := &amp;http.Client{Jar: jar, Timeout: 5 * time.Second}
  
  // First Request
  
  req, err := http.NewRequest("GET", loginURL, nil)
  if err != nil {
      return "", fmt.Errorf("Failed to authenticate with Google\n Details: \n\n Username: %s\n Password: %s\n AuthType: %s\n", details.Username, details.Password, details.AuthType)
  }
  req.Header.Set("User-Agent", "niantic")
  resp, err := newClient.Do(req)
  if err != nil {
      return "", fmt.Errorf("Failed to send intial handshake: %v", err)
  }
  respJSON := make(map[string]string)
  err = json.NewDecoder(resp.Body).Decode(&amp;respJSON)
  if err != nil {
      return "", fmt.Errorf("Failed to decode JSON Body: %v", err)
  }
  
  resp.Body.Close()
  
  // Second Request
  
  form := url.Values{}
  form.Add("lt", respJSON["lt"])
  form.Add("execution", respJSON["execution"])
  form.Add("_eventId", "submit")
  form.Add("username", details.Username)
  form.Add("password", details.Password)
  req, err = http.NewRequest("POST", loginURL, strings.NewReader(form.Encode()))
  if err != nil {
      return "", fmt.Errorf("Failed to send second request authing with PTC: %v", err)
  }
  req.Header.Set("User-Agent", "niantic")
  req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
  resp, err = newClient.Do(req)
  if err != nil {
      return "", fmt.Errorf("Failed to send second request authing with PTC: %v", err)
  }
  log.Println(resp.Location())
  ticket := resp.Header.Get("Location")
  
  if strings.Contains(ticket, "ticket") {
      ticket = strings.Split(ticket, "ticket=")[1]
  } else {
      return "", fmt.Errorf("Failed could not get the Ticket from the second request\n")
  }
  resp.Body.Close()
  </code></pre>
  
  <p>But when I <code>log.Println(resp.Location())</code> I get <code>&lt;nil&gt;</code></p>
  
  <p>I'm really not sure what the differences are here (I've tried with and without the <code>Content-Type</code> header but for some reason I just can NOT get the Location header that I'm looking for.</p>
  
  <p>I really can't see a discrepancy between the Node request, vs the Go request but any help would be great as I have been beating my head off the wall for the last day. Thanks.</p>