aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes I tried to send an xml to an url its , Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "I tried to send an xml to an url its ," Watch "I tried to send an xml to an url its ," New topic
Author

I tried to send an xml to an url its ,

Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
I tried to send an xml to an url its ,
throwing error when its tries to opens connection to the URL (url.openStream())

URL url = new URL("http://xx/yy?xml=test xml");
connection.setDoOutput(true);
connection.setDoInput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));


But when i tried to connect to the url directly from the browser i could able to connect.Only through the code i'm getting the error.






Please help me..
thanks you.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

HTTP is a request-response protocol. Many servers will not start to process a request until the client opens the response. Try reading from your BufferedReader.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
I'm reading only from,


BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));




Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

You create the reader, but do you also read all data from it?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
Yes, i tried to read,



But i'm getting error at this place itself,
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Is the server reachable from the machine where this code is run? Meaning, can you retrieve that URL by copying it into a browser?


Ping & DNS - my free Android networking tools app
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
same url can be accessed and able to get reply from browser , the problem comes when trying to connect from code
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

Are you using a proxy in your browser? If so, you must also use that proxy in your code:

Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
Yes, i'm using Proxy address for connecting to internet,

Is this is the way to set Proxy,



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

That looks alright to me.
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
but still its throwing same (timeout error) at this line,

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

That's because url.openStream() is shorthand for url.openConnection().getInputStream() - and therefore does not use the proxy. In my code example I've shown you to use connection.getInputStream() instead.
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
How to get the proxy address dynamically.Because if i put the code in some other system the proxy may change.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

I don't think you can get that without using either JNI or the registry.
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
The has been solved.thanks for your valueable input and time.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

Do you care to tell us how you did this?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I tried to send an xml to an url its ,