Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How would I go about silently opening up a HTTP connection to a certain website in Java?
I tried .openConnection() and it didn't work.
You need to find out why .openConnection() isn't working. Catch the exception thrown by that call and print out the exception's full stacktrace. That should give you the information you need to start diagnosing.
The javadoc for URL.openConnection() says this:
"It should be noted that a URLConnection instance does not establish the actual network connection on creation. This will happen only when calling URLConnection.connect()."
That call can occur explicitly or implicitly; i.e. when you attempt to read the response status, headers or body. Read the javadocs for URLConnection and HttpURLConnection for more details.
So it sounds like openConnection is working ... but it doesn't do what you expect it to.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
this is my first question here, so sorry if I broke some rules.
Anyway...
I'm trying to connect to a SQL Server database but I'm constantly getting Null Pointer Exception error even though I'm pretty sure that I've set all parameters correctly and imported the right driver into my Apache NetBeans project
screenshot 1 - https://i.stack.imgur.com/kTaz6.png
screenshot 2 - https://i.stack.imgur.com/6nhu2.png
screenshot 3 - https://i.stack.imgur.com/qQOS3.png
Database listen in the first screenshot is definitely created in SSMS while usr, pass and prt are also correct.
Can someone tell me why I can't create a connection?
Thanks in advance!
I guess, there´s an exception, which isn´t logged in the creation of the connection in class DB in line 25.
You catch the SQLException, but don´t do anything with it. Try a e.printStacktrace() in the catch block, to get a clue what´s going wrong.
By the way (for next time):
It´s much easier to follow and try out your code if you send it as text in the question instead of screenshots.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
We are planning to develop an API. There are so many cases that a request can be considered as a bad request.
For this, We have planned to send a JSON object with error code, error,
and additional info
I have put the sample case here when a user sends an illumination image. We considered as this request is bad request and send the following JSON
{
"ErrorCode": 10000,
"Error": "Detected uneven illumination image",
"Additional Info": "Prefer to change the image location"
}
Is our JSON object format is good or we need to add the HTTP Error code like 400/404
How to select this custom error code? We are planning to take the error code number from 10000.
Can someone please help us or provide some trustful resources?
Check Stripe API they also use error codes (code) to explain different 4xx errors
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Why query string is not getting created in doPost method of HttpServlet?
Is this reason is enough - it is supplying data in html body.
can anyone please clarify what actually happening
Get and post methods are almost the same, the only difference between these two methods is that: in post, query strings (name/value pairs) is sent in the HTTP message body of a POST request and in get, query strings (name/value pairs) is sent in the URL.
Why is this done this way, obviously, security reasons.
You do not want to see your login credentials in the url.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to set SO_LINGER socket option to ServerSocket? Should i extend SocketImpl class. But there are many abstract methods in SocketImpl class.
Set it on the Socket that you get from serverSocket.accept().
You can't set SO_LINGER on a ServerSocket. It doesn't make sense.
I'm wondering whether you even know what SO_LINGER is for. It is a very rarely used technique for enforcing a close timeout on connected TCP sockets, or, unfortunately, for forcing them to reset the connection when closed, which is an operation by far best avoided for many reasons, much-abused, and little understood.
You almost certainly don't want to use it at all on any socket whatsoever.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm going to get Html responses and do some modifications on responses in Java before they reach client.
My idea is writing a servlet-filter but I don't know how to implement that.
What I got is :javax.servlet.ServletResponse resp and javax.servlet.ServletRequest req.
The essentials of filters
check the part on modifying responses
In your servlet filter, you can provide your own subclass of HttpServletResponseWrapper
After the call of chain.doFilter(...), your response wrapper will contain the html content, you'll be able to retrieve and transform it.
You can find a similar servlet filter there as example : http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html
use head first's chapter for filter there is an example of HttpServletResponseWrapper. very nice book for servlet and jsp s.