Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

posting xml to a URL

Posted on 2012-03-13
12
Medium Priority
?
182 Views
Last Modified: 2012-03-24
To post data to a URL, let's say (http://999.99.99.99:9999), does the url need to be concatenated with any addtional syntax or it is as simple as
opening the connection,  setting doOutput to true, and then creating an outputStream
and then writing to it?

Do I need to flush the outputStream too?
0
Comment
Question by:dpalyca755
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37718181
You need to have some active enitity behind that URL which would read your data - it should be servlet or PHP script or CGI, or something which should be a process ready to accept your data

Then you indeed acn setDoOutput(true), etc. like in this example:

http://www.exampledepot.com/egs/java.net/post.html
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37718189
It usually is more than just address and port because the URL mentions that active entity which accepts your data. I don't think it is an absolute law, I guess you can invenet something to make this script accept your data by deafult on certain address and port, but as a rule after address and port you mention the name of that script which accepts your data, name of servlet or PHP ascript or something like that
0
 

Author Comment

by:dpalyca755
ID: 37718291
If I create a URLConnection and open it, but do not open an outputStream on it yet, will I see activity on the server side socket or is it not until the stream is opened?
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 47

Expert Comment

by:for_yan
ID: 37718300
I am not sure how you mean to see activity on the server side socket until the stream is opened.
0
 

Author Comment

by:dpalyca755
ID: 37718313
If I am polling the socket on the URL's code will something be sent when the line
URLConnection con = url.openConnection(); is invoked, or is nothing sent until
con.getOutputStream() line in executed?
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 2000 total points
ID: 37718318
No it does not start communicating until you get stream; read the accepted solution here:
http://stackoverflow.com/questions/39391/does-new-url-openconnection-necessarily-imply-a-post
0
 

Author Comment

by:dpalyca755
ID: 37718339
Ok...so if the connection is refused upon opening the outputStream, a response or exception will be raised as long as the conn.getOutputStream() is in a try block,
or do I also need to open an inputStream to receive the potential reject?
0
 

Author Comment

by:dpalyca755
ID: 37718346
Also: for inputStreams I would expect to see the server side socket get hit once with a GET query, whereas should I expect the outputStream to hit the socket twice, ie.. once with a POST and no data, and the the data from the actual write()?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37718355
>or do I also need to open an inputStream to receive the potential reject?

I don't think there could be an universal answer to that question.
If you get no response say because you have incorrect address, then it makes no sense to open input stream. If you are rejected by the script in your URL which analyzed the data and prepared some srror message - then maybe inputStream will be necessary

i think it is better to deal with this situation using very concrete example - what kind of URL you are contacting and what you want to achieve. There are many variants of different types and situations of failures and we'll not predict all cases theoretically
0
 

Author Comment

by:dpalyca755
ID: 37718368
I will need to ask the url developer I am working with this question.
When you say "what type of URL"?  What are you asking for exactly?
0
 

Author Comment

by:dpalyca755
ID: 37718374
All I know at this moment is it is a http url to which I want to post XML data to.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 37718383
If I were you I'd try to use the code along the line of this example:
http://www.exampledepot.com/egs/java.net/post.html
and then see what is happening.
If you see the problems then ask the URL developer if it is someone you could contact
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question