my dog learned polymorphism*
The moose likes Sockets and Internet Protocols and the fly likes Accessing the URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Accessing the URL" Watch "Accessing the URL" New topic
Author

Accessing the URL

Pranit Sonawane
Ranch Hand

Joined: Jul 29, 2011
Posts: 155

Hello all Here is my code



and this returns me


Somebody Please Suggest me Something!
Thanks in Advance!


And oh Yes, I'm writing this in a java swing app.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Suggestion: as you may notice from the URL you posted, the space in it causes everything after the space to be ignored. Or, as with your server, it causes the URL to be rejected. That's because it's not a valid URL with that space in it. The parameters need to be URL-encoded. And for that there's a java.net.URLEncoder class with a suitable static method to do that.
Pranit Sonawane
Ranch Hand

Joined: Jul 29, 2011
Posts: 155

Alright now i have a URL to access and when copy and paste it in the browser directly it works fine and I immediately receive an SMS, but when I do save from my swing app, it returns HTTP Response code : 400? Any clues?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Then the browser is sending information that your application is not sending. Since the URLs are the same, that would mean that the browser is sending HTTP headers which your code is not sending. So, you should use some browser debugging tool which allows you to inspect the headers attached to a successful request. I use HttpFox in Firefox but quite likely there are newer and/or better tools, or tools available for the browser you might be using.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

By the way... it's quite possible that the server is doing certain tests to make sure you're using a browser to enter your SMS data. It may be possible to circumvent those tests, but before you do that I would recommend reading the site's terms of reference (the terms I suppose you agreed to when you got your user ID). If they prohibit the use of automated connections to the site, then the code you are trying to write would be a violation of those terms.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing the URL
 
Similar Threads
url reader applet
Need Help --- Response XML Tag Value
output in a file
about URL access (Please help me
intro and i dont understand this code