• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading parameters in response using URL connection

 
Baz Matt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im making a HTTPS POST to a service from a Java class using HTTPS URL connection by preparing a query string and writing it to the output stream. Then I try reading the response from the input stream. The 3rd party service that sends the response sends back a redirect to a URL with parameters. However, when I read the response, Im getting the HTML content of the page corresponding to the URL. And,I`m missing the parameters. Is there any way I can read the parameters or any other way to intercept the response from the service? Appreciate any inputs/suggestions.Thanks
 
Paul Clapham
Sheriff
Posts: 21872
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on what class and methods you're using to do the POST. The standard HttpURLConnection class has methods which control whether redirects should be followed automatically, so if you're using that class, you should set it to not follow redirects. Otherwise if you're using some other class you should investigate to see if it has a similar feature.
 
Baz Matt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I`m using HttpURLConnection. So, If I send a request and get redirected to, lets say http://someIPAddress:80/Test.jsp;token=!MASKasdfhjdasjvdsahdMASK!,
where I`m currently getting the entire HTML page as a String when reading the InputStream, is it still possible to read the parameter token that comes with it?
 
Baz Matt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to get hold of the redirected URL as I wanted by using the getURL method after getting the InputStream.
Calling it before gettng the InputStream method yielded the URL I was calling and invoking it after getting the InputStream,
yielded the redirected URL.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!