Picking Location from a POST

1

I'm using the HttpRequestHeader method to make requests ( GET and POST ), however I'm getting the Location parameter from the response of a POST and I'm not able to evolve. You have an example of my request below:

url = "https://www.google.com"
        req = HttpWebRequest.Create(url)
        req.Method = "POST"
        req.Headers.Add(HttpRequestHeader.Cookie, sessao)
        req.Headers.Add(HttpRequestHeader.AcceptLanguage, "pt-BR")
        req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0"
        req.Referer = "www.google.com.br"
        req.ContentType = " multipart/form-data; boundary=---------------------------24708330210100"
        req.ContentLength = postData.Length

        Dim swRequestWriter As StreamWriter = New StreamWriter(req.GetRequestStream())
        swRequestWriter.Write(postData)
        swRequestWriter.Close()

        Dim srResponseReader As StreamReader = New StreamReader(req.GetResponse().GetResponseStream(), System.Text.Encoding.UTF7)

        html = srResponseReader.ReadToEnd().Trim

Remembering that the addresses are fictitious, I would like an urgent help.

    
asked by anonymous 25.02.2015 / 21:46

2 answers

1

I think I get Header solves what you need. Replace the end of your code with something like this:

using (var response = req.GetResponse()) {
    var location = response.Headers["Location"];
    using (var srResponseReader = new StreamReader(response.GetResponseStream())) {
        html = srResponseReader.ReadToEnd();
    }
}
    
25.02.2015 / 21:59
0

I think you have to get and check the Header

HttpWebResponse response = myRequest.GetResponse();

// verifica se existe o location
if( response.Headers["Location"] == null ) {    
}
else{
}
    
26.02.2015 / 16:16