Jump to content

Http Post- Redirect Response


Recommended Posts

I have been using http post for a long time and now i have came across a problem..

 

After i have sent the post request

$url.Send($post)

$header = $url.GetResponseHeader("HOWTOGETALLHEADERS")

FileWrite('crash.txt',$header)

there is an error saying "requested action with this object has failed". It is because error is requested header was not found.

I have been using $url.ResponseText and $url.StatusCode for a long time, but now i have to get the headers which server sends to me in response for my project..

So i found $url.GetResponseHeader in https://www.autoitscript.com/forum/topic/115676-http-get-headers/ this link, but I want to get all headers which comes with response.

Is there any way of getting all headers?

Also is there any documentation providing all things which can be done with the response from server (like statuscode, responsetext and all like that)?

 

Edited by KeshHERE
Link to comment
Share on other sites

I think GetResponseHeader requires a parameter (header name to be returned)

 

If you want to get whole header you can use getAllResponseHeaders

 

Saludos

Link to comment
Share on other sites

11 minutes ago, Danyfirex said:

I think GetResponseHeader requires a parameter (header name to be returned)

 

If you want to get whole header you can use getAllResponseHeaders

 

Saludos

Wow great thanks..

But as i had to ask it here, Is there any documentation in autoit for all things we can do with response?

 

Link to comment
Share on other sites

AutoIt is just the bridge for using the Windows HTTP Request. you should see the possibilities inside Windows HTTP Request.

 

Saludos

Link to comment
Share on other sites

I have got another problem..

My post request gets the response which has

Server: 
Set-Cookie: 
Location: http://somewebsite.com/dashboard
Content-Length: 
Date: Mon, 18 Jul 2016 15:48:13 GMT

 

problem is , it is inevitable sending the second http GET request to the URL in "Location" (Site is problably programmed to do that because response code is 302 which is for url redirection).. and it also gets response.

So my code doesnt get above shown response but delivers the response made by that http GET request..

Any work around?

Edited by KeshHERE
Link to comment
Share on other sites

I think you need to go step by step. try to find http viewer  and try to reproduce what you want. and if you want to get more help you should post working examples to be easy support you.

 

Saludos

Link to comment
Share on other sites

4 minutes ago, Danyfirex said:

I think you need to go step by step. try to find http viewer  and try to reproduce what you want. and if you want to get more help you should post working examples to be easy support you.

 

Saludos

I cant post the code cause it is for login..

 

Basically i am login in using http post and it works, but after logged in it redirects to dashboard, so that wht i am getting as response of my code is the response of dashboard, not my login response.

Link to comment
Share on other sites

I am trying to get response headers by sending HTTP POST request to on server..

But the problem is , the first response is Redirect ..

First response header is like this:-

HTTP/1.1 302 Found
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=SomeID; Path=/; HttpOnly
Location: http://Somewebsite.com/dashboard
Content-Length: 0
Date: Tue, 19 Jul 2016 10:09:39 GMT

So it automatically redirects to another site which is in "Location header" of first response.. and give me the second response.

second response headers:-


HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Content-Language: en-IN
Content-Length: 5683
Date: Tue, 19 Jul 2016 10:09:39 GMT

 

The script i am using to obtain headers is as below..

#include <IE.au3>

$loginurl ="http://Somewebsite.com/Login_check"
$login = ObjCreate("winhttp.winhttprequest.5.1")

$login.Open("POST",$loginurl, False)

$login.SetRequestHeader('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
$login.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
$login.SetRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.25.2704.63 Safari/537.36')
$login.SetRequestHeader('Origin', 'http://Somewebsite.com')
$login.SetRequestHeader('Accept-Encoding', 'gzip, deflate')
$login.SetRequestHeader('Referer', 'http://somewebsite.com/logout')
$login.SetRequestHeader('Accept-Language', 'en-US,en;q=0.8')

$post='username=UserName&password=PassWord'

$login.Send($post)

$header=$login.GetAllResponseHeaders
FileWrite('headers.txt',$header)

Now the problem is, I want to obtain "First response" as stated above, but due to redirect, this script give me second response due to redirect..

Is there any way to get First response and save it in text file or something, by stopping redirect or anything?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...