sentence
stringlengths 1
1.38k
| label
stringclasses 3
values |
---|---|
URL_http://java.sun.com/javase/6/docs/api/java/net/HttpURLConnection.html In particular, getHeaderField, getHeaderFieldKey, and getContent.
|
o
|
[There's a mini tutorial here at SO]( URL_http://stackoverflow.com/questions/2793150/how-to-use-java-net - urlconnection-to-fire-and-handle-http-requests).
|
o
|
From URL_http://java.sun.com/docs/books/tutorial/networking/urls/readingWritin g.html [Sun's-java-tutorial] CODESNIPPET_JAVA1 .
|
o
|
The strange thing is that some servers will reply you back with strange ?
|
o
|
characters (which seems like an encoding error related to request headers but not) if you don't open an output stream and flush it first.
|
o
|
I have no idea why this happens but will be great if someone can explain why?
|
o
|
@Gorky: Make a new question.
|
o
|
You can use URL_http://download.oracle.com/javase/7/docs/api/java/net/HttpURLC onnection.html [java.net.HttpUrlConnection] .
|
o
|
Or maybe this link is easier to read: URL_http://www.xyzws.com/Javafaq/how-to-use-httpurlconnection-post-data-to- web-server/139 [ URL_http://www.xyzws.com/Javafaq/how-to-use-httpurlconnection - post-data-to-web-server/139] If Java Almanac is down, try URL_http://www.xyzws.com/Javafaq/how-to-use- httpurlconnection-post-data-to-web-server/139 [this-one] .
|
p
|
Microsoft?
|
o
|
This is Java.
|
o
|
What does Microsoft have to do with it?
|
o
|
I know I'm late to the party here...but I'm currently frustrated with the Java APIs lack of examples.
|
n
|
I guess MSDN spoiled us.
|
n
|
Late, indeed.
|
o
|
The response is three years old.
|
o
|
What didn't you find at Java Almanac?
|
o
|
And how is this comment helping?
|
o
|
Nothing stops you from going back to Microsoft.
|
o
|
Or stay and learn to like all the open source stuff that Java gives you.
|
p
|
FYI the Java Almanac link is dead (or at least there are no code snippets).
|
o
|
FYI - I answered this three years ago.
|
o
|
Here is another nice code snippet in replace for Java Almanac: [HttpUrlConnection-Example]( URL_http://www.xyzws.com/Javafaq/how-to-use - httpurlconnection-post-data-to-web-server/139).
|
p
|
Can you show some example code perhaps?
|
o
|
Scott, isn't the link in the comment just above yours enough for you?
|
o
|
And did you have the gall to downvote this?
|
o
|
BTW the Java Almanac link from above now goes to Adult Friend Finder (surprise!
|
o
|
- NSFW).
|
o
|
Dude, I wrote that answer four years ago.
|
o
|
Thanks for alerting me.
|
o
|
URL_http://hc.apache.org/ [Apache-HttpComponents] .
|
o
|
The examples for the two modules - URL_http://hc.apache.org/httpcomponents-core-ga/examples.html [HttpCore] and URL_http://hc.apache.org/httpcomponents-client-ga/examples.html [HttpClient] will get you started right away.
|
o
|
Not that HttpUrlConnection is a bad choice, HttpComponents will abstract a lot of the tedious coding away.
|
n
|
I would recommend this, if you really want to support a lot of HTTP servers/clients with minimum code.
|
p
|
By the way, HttpCore could be used for applications (clients or servers) with minimum functionality, whereas HttpClient is to be used for clients that require support for multiple authentication schemes, cookie support etc.
|
o
|
FWIW, our code started with java.net.HttpURLConnection, but when we had to add SSL and work around some of the weird use cases in our screwy internal networks, it became a real headache.
|
n
|
Apache HttpComponents saved the day.Our project currently still uses an ugly hybrid, with a few dodgy adapters to convert java.net.URLs to the URIs HttpComponents uses.
|
n
|
I refactor those out regularly.
|
o
|
The only time HttpComponents code turned out significantly more complicated was for parsing dates from a header.
|
o
|
But the [solution]( URL_http://stackoverflow.com/a/1930240/1450294 ) for that is still simple.
|
p
|
I know others will recommend Apache's http-client, but it adds complexity (i.e., more things that can go wrong) that is rarely warranted.
|
n
|
For a simple task, CODETERM1 will do.
|
p
|
CODESNIPPET_JAVA1 .
|
o
|
That doesn't help if you want to monkey with request headers, something that's particularly useful when dealing with sites that will only respond a certain way to popular browsers.
|
p
|
You can monkey with request headers using URLConnection, but the poster doesn't ask for that; judging from the question, a simple answer is important.
|
p
|
This will help you.
|
o
|
Don't forget to add the JAR CODETERM1 to the classpath.
|
o
|
CODESNIPPET_JAVA1 .
|
o
|
There's a great link about sending a POST request URL_http://web.archive.org/w eb/20120101100355/ URL_http://www.exampledepot.com/egs/java.net/Post.html [here] by Example Depot:: CODESNIPPET_JAVA1 .
|
p
|
If you want to send a GET request you can modify the code slightly to suit your needs.
|
o
|
Specifically you have to add the parameters inside the constructor of the URL.
|
o
|
Then, also comment out this CODETERM1 One thing that's not written and you should beware of, is the timeouts.
|
o
|
Especially if you want to use it in WebServices you have to set timeouts, otherwise the above code will wait indefinitely or for a very long time at least and it's something presumably you don't want.
|
n
|
Timeouts are set like this CODETERM2 the input parameter is in milliseconds .
|
o
|
Here's a complete Java 7 program: CODESNIPPET_JAVA1 .
|
o
|
The new try-with-resources will auto-close the Scanner, which will auto-close the InputStream.
|
o
|
You may use Socket for this like CODESNIPPET_JAVA1 .
|
o
|
shouldn't it be \r\n instead of \n?
|
o
|
@Troelsen yes correct!.
|
p
|
Suggest a simple NoSQL database for java project.
|
p
|
I am developing a simple internal use application with an intended user base of around 100 people.
|
p
|
The application does a lot of reads and very few writes.
|
o
|
The dataset size is fairly small and we do not want to use a RDBMS if possible.
|
o
|
In fact, the relational requirements are fairly small.
|
o
|
I am looking at using some NoSQL database and I am looking for one with the following requirements.
|
o
|
1.
|
o
|
A simple, stable implementation which can be accessed easily from Java (i.e has a Java client).
|
p
|
2.
|
o
|
I would like to be able to run a test application from a Windows box although the final deployment is on a Linux box.
|
o
|
3.
|
o
|
Setup of the NoSQL DB should be minimal.
|
o
|
4.
|
o
|
I am not concerned with scaling the DB because we expect to limit the dataset size and trim old data occasionally.
|
o
|
Any suggestions would be helpful.
|
p
|
I am currently considering URL_http://code.google.com/p/redis/ [redis] + URL_http://code.google.com/p/jredis/ [jredis]
One of my main motivations for this project is also to look into the programming model and ways of usage of NoSql DBs.
|
p
|
I understand I can use flat files, blobs etc.
|
o
|
Since simple flat files require no setup and don't use SQL, what are you asking?
|
o
|
@S.Lott - Agreed.
|
o
|
I also want to use the opportunity to do a starter project using a NoSQL database.
|
o
|
Serializing is simple.
|
p
|
URL_http://download.oracle.com/javase/6/docs/api/java/io/Serializable.html .
|
o
|
@Thimmayya: then this is a rhetorical question.
|
n
|
Use what you think will be fun.
|
n
|
@msw - It is rhetorical :).
|
n
|
Just want to see if there are any suggestions that I may not have found while googling.
|
o
|
@offtopic but I don't like these databases being called NoSQL, it seems that the emphasis is on not having sql though the reality is that these database lack relational schema and thats why people want it not because they don't want to use sql.
|
n
|
"I also want to use the opportunity to do a starter project using a NoSQL database"?
|
o
|
What does that matter?
|
o
|
Since simple flat files require no setup and don't use SQL, what are you asking?
|
o
|
What's wrong with flat files?
|
o
|
Why ask?
|
o
|
@S.Lott - There is nothing wrong with flat files for a simple app.
|
n
|
I just want to explore some of the new NoSQL DB systems and the programming model associated with them.
|
o
|
I am not sure if you are upset with the question, but since I did not find the same question already answered and the community here is friendly enough with such questions, I figured I would go ahead and ask for opinions.
|
p
|
Relax man.
|
o
|
@Thimmayya: Then don't use "NoSQL" -- it's too vague to have any meaning.
|
o
|
The Flat File is the perfect NoSQL database.
|
p
|
Why not use it?
|
o
|
In this case, you don't want to use flat files because when you say "NoSQL" you mean something specific -- "redis".
|
o
|
Please fix your question to remove the vague and poorly- defined "NoSQL" and be more specific about what you want opinions on.
|
n
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.