Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the redirect url and reuse this url to do get operation? #34

Open
richzw opened this issue Jun 15, 2012 · 8 comments
Open

How to get the redirect url and reuse this url to do get operation? #34

richzw opened this issue Jun 15, 2012 · 8 comments

Comments

@richzw
Copy link

richzw commented Jun 15, 2012

hi Charlie,

When I do a post operation and want to get the new url information from redirection. so I can do the new get operation.
I do not how to do that? Could you please help me?

code:
suite.discuss('now we create a project')
.use('localhost', 3000)
.setHeader('Content-Type', 'application/json')
.followRedirect(false)
.path('/projects')
.post( { information : 'good news'})
.expect(302)
.expect('redirect content', function(err, res, body){
...

I know that I can get the url from res.headers.location, but how can I do a get operation with this url??

@richzw
Copy link
Author

richzw commented Jun 15, 2012

also if I set .followRedirect(true), I can not get the 200, which mean API-easy can not support it now?

@cronopio
Copy link

I guess the quick an easy solution is have a variable and store there the url.

var urlRedir;
suite.discuss('now we create a project')
.use('localhost', 3000)
.setHeader('Content-Type', 'application/json')
.followRedirect(false)
.path('/projects')
.post( { information : 'good news'})
.expect(302)
.expect('redirect content', function(err, res, body){
  urlRedir = res.headers.location;
})
.get(urlRedir)

I dont know if suit for you

@richzw
Copy link
Author

richzw commented Jun 26, 2012

hi Daniel,

I try your code, but the urlRedir in get() method is undefined.

then I add .next() before .get(urlRedir), however, it does Not work.

any idea for that?

@tomekc
Copy link

tomekc commented Jul 11, 2012

I have the same problem, I'd like to save some value returned by one query and use it in next query (as a parameter, for example). I came up @cronopio suggestion on my own, but it is not working (variable is undefined).

@cronopio
Copy link

I dont what can be. I have a couple of projects doing that and work. Can you share some gist with the code you have?

@richzw
Copy link
Author

richzw commented Jul 19, 2012

Thanks @cronopio
I find it can work well with this code

.followRedirect(false)
.path('/projects')
.post({project: { name : 'hf1sp3'

However, I use the following code before and the urlRedir is undefined

.followRedirect(false)
.post('/projects', {project: { name : 'hf1sp3'

I think the two codes are same, but it is not.
why?

@richzw
Copy link
Author

richzw commented Jul 22, 2012

@cronopio

I am sorry that I have made some mistakes. the urlRedir is undefined. Both post and get use the same url /projects

For details, please refer to https://gist.github.com/3156327

@ajostergaard
Copy link

Switching back to pure vows due to this 'undefined' issue. :-|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants