This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading parameters in response using URL connection  RSS feed

 
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: 22498
43
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!