Can't get HttpURLConnection to work on sites that require passwords

Help!
I can't seem to get this code to work. I have found numerous sites
that show the same code that I am using.
I am using jdk 1.5 and trying to generate the
"Authorization: Basic erwerwqerwerwer" line in the http get header. I
have tried the "Authenticator.setDefault (new MyAuthenticator ());"
route and it did not work. I have found a lot of web sites with the
code snippets
// Build the string to be used for Basic Authentication
<username>:<password>
String userPassword = "username:password";
// Base64 encode the authentication string
String encoding = new sun.misc.BASE64Encoder().encode
(userPassword.getBytes());
URL url = new URL ("http://www.server.com");
HttpURLConnection connection =
HttpURLConnection)url.openConnection();
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Authorization", "Basic " +
encoding);
connection.connect();
BufferedReader in =
new BufferedReader (new InputStreamReader
((InputStream)url.getContent()));
String line;
while ((line = in.readLine()) != null) {
pw.println (line);
but none of this works. All I get is:
GET / HTTP/1.1
User-Agent: Java/1.4.2
Host: www.server.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Either the JDK does not work or I am doing something stupid. Help!
Please? I am about to just say screw it and use a raw socket and write
the get request manually.
Thanks!

My god! Is it me or is everyone finding ways to avoid my question? How can I explain this any better?
Encoding is not the problem. If there is a problem with the way I encode the user:password String, it is a separate issue. I have included the CGI transaction between my program and the server in my original question to illustrate the problem.
If you looked at it, you would realize it does not matter what was encoded because it was never included in the GET request. Didn't I show that in the original posted question? That was the point of my question.
here is another example of a GET request that would work:
GET /admin.cgi HTTP/1.1
Host: www.server.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113
Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Authorization: Basic kdkkseeoefksakf
Cache-Control: max-age=0
It is from a sniffer dump of the transaction between my browser and the web site (the URL and username:password are changed). That is the correct CGI transaction to get a web page from a password protected URL.
Now the sniffer dump from my Java code using HttpURLConnection :
GET /admin.cgi?mode=viewxml HTTP/1.1
User-Agent: Java/1.4.2
Host: www.server.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Encoding the password or putting a space between "Basic" and the encoded password string do not even come into the problem yet.
Is everyone asleep here or did I just not use the secret handshake and everyone is just screwing with me?

Similar Messages

  • With some (not all) sites that require passwords, how do I get Firefox to resume saving passwords when the site is not in the exception list?

    For some banking sites that require passwords, I am 99.3% sure I at some time said "never remember passwords." Now I want to change my mind. When I go to Options/Options/Security/Remember.../Exceptions, the sites are not listed, but I still am not asked the question 'Want to remember....'

    Thanks for your help and your quick reply, cor-el!
    I did install the view passwords bookmarklet; it worked properly. I installed the saved-password-editor, and I think I entered all fields correctly, although (1) I was not sure of the meaning of the field 'submit prefix' and used the 'guess from current page' button, and (2) I winged it using the default on both the username field name and the password field name because the guess button simply said 'fill this form based on a likely login form on the current page.' [Does the button pick up that name?]
    After fumbling a while, everything got to working! So, THANKS! Although I'm still not sure what the 'view passwords' bookmarklet does for me, since I do know the needed passwords.
    I'm going to leave this open for one more day, since as a first-time user I don't know whether messages are added (such as explanations to my above minor issues) after I acknowledge the problem solved. I'll do that tomorrow.

  • Can't get links to work on site--

    The name links don't work for me on the link below. Im sure other things don't as well. I have no problems on other sites and I wonder why this can't be fixed. I have ask SOA but got on reply. I am using Mac OX10.4.11 any help?
    I've used firefox, netscape, icab, safari and no luck.
    Any ideas, Thanks
    http://www.soaphoto.com

    Re-ask....

  • HT1766 my daughters iphone is disabled and i can not get it to work or sync without the password and its locked

    she really never used the icloud on her phone so i do not know what to do

    You will need to try to restore your iPhone from the same computer that you most recently synced to.
    Read this: http://support.apple.com/kb/ht1212
    If you can't do the restore then you will need to try Recovery Mode.
    Read this: http://support.apple.com/kb/ht1808
    Follow the instructions very carefully.

  • I can't get Itunes to work after message that it was successfully installed.  Error message MSVCR80.dll was not found  Error 7.  Help?

    Help?

    Click here and follow the instructions. You may need to completely remove and reinstall iTunes and all related components, or run the process multiple times; this won't normally affect its library, but that should be backed up anyway.
    (99229)

  • Can Muse be used to create a site that requires a CMS with multiple user accounts?

    Hi, I am new to Adobe Muse and I would like to understand some specific things about the software. I have been comissioned to create a gallery website which requres a cms for use with mulitple accounts for the users/ artists to display seperate profiles and submit work to. Does Muse have this functionality and if possible to answer, how would I do this? I have looked at the tutorials on Adobe for Muse but I have not seen anything related to this, only the Busines Catlalyst website management software (if indeed it is software). Are there any tutorials on this or could I please be directed to one if no direct answer can be given here as I appreciate it is quite an indepth question. Thanks..

    Wait for the new version of Muse which should be published during the first quarter of this year. I guess that in the new Muse version could be basic CMS features?
    Best Regards
    TaikaJim

  • Can't get sound to work [SOLVED]

    Hi, I'm new to arch/linux in general. Built a computer, and can't get sound to work. I ran Ubuntu for a short period of time, and sound worked there, so I'm assuming there's no hardware issue here.
    I'm a little bit stuck as to what I should be doing. Help?
    Last edited by uma (2012-01-28 22:51:25)

    Start with the wiki: https://wiki.archlinux.org/index.php/Ad … chitecture
    If you still can't figure it out and you want help, at least post some info, instead of 'can't get it to work' (this implies that you tried something, but what?).

  • After reinstall, can't get sound to work

    I did a full reinstall of windows XP to a new hard dri've after my old one crashed, and I can't get the sound card to work. I am getting no sound whatsoever.
    I have the Soundblaster? X-fi disc that came with my Dell computer, and I used that to install drivers. Device manager says the card and drivers are working properly. It also lists a Sigma Tel High Definition Audio Codec as a device, which is something that was on the driver disk supplied by Dell. I disabled that just in case the two are in conflict, but no luck. I would appreciate any advice. Thanks.

    Start with the wiki: https://wiki.archlinux.org/index.php/Ad … chitecture
    If you still can't figure it out and you want help, at least post some info, instead of 'can't get it to work' (this implies that you tried something, but what?).

  • I can't send mail to the site that required Authenticator

    How can I send mail to the smtp site that required Authenticator,If th smtp site doesn't require Authenticator ,I can send mail.
    My program:
    Properties props=new Properties();
    props.put("smtp","smtp.163.com");
    props.put("auth","true");
    MailUser mu=new MailUser("username","password");
    javax.mail.Session session=javax.mail.Session.getDefaultInstance(props,mu);
    public class MailUser extends Authenticator
    String username;
    String password;
    public MailUser(String us,String ps)
    this.username=us;
    this.password=ps;
    }

    Properties props = System.getProperties();
    props.put("mail.smtp.host", "hiart.co.kr");
    props.put("mail.smtp.auth","true");//auth module....
    session = Session.getDefaultInstance(props,null);
              Date date = new Date();
    msg = new MimeMessage(session);
              System.out.println(from);
    msg.setFrom(new InternetAddress(from+"@hiart.co.kr"));

  • I can't get java to work on my Mac. It is installed and enabled. I can't activate java per site because I don't get "click here to activate" box.

    I can't get java to work with Firefox on my mac with OS 10.6.8. I did everything suggested and still no luck. Java is installed, enabled, and updated. I can't even activate java per site because I don't get the "click here to activate" box for some reason. Apple support said it's a firefox problem and they can't help me. I need to be able to use java!

    hello, please update firefox to the latest version & your OS to 10.6.8.
    [[Update Firefox to the latest version]]
    http://support.apple.com/kb/HT4561

  • I have Nortons security suite under the old version the Idenity protection worked I kept all my passwords under this which used a master pasword I did not save passwords any were else and now can not get it to work supplying passwords for my l0gon site.

    I have Norton's security suite under the old version the Idenity protection worked. I kept all my passwords under this which used a master pasword I did not save my passwords any were else and now can not get it to work supplying passwords for my logon site.

    Symantec need to correct a mistake they made with their add-ons. They originally updated their add-ons after quite a delay to work with Firefox 4.0 as shown here - http://community.norton.com/t5/Norton-Internet-Security-Norton/Firefox-4-compatibility-hotfix-is-now-available/td-p/428894
    They made an error with the update in only listing it as compatible with Firefox 4.0, so they will not install on Firefox 4.0.1 and subsequent Firefox security updates. Symantec have indicated they will be releasing an update to correct their error soon, for details see http://community.norton.com/t5/Norton-Internet-Security-Norton/Norton-Toolbar-not-compatible-with-FF-4-0-1/td-p/442788/page/12

  • Port 8080: I know this is simple, I just can't get it to work.

    I'm trying something that I'm sure is relatively simple. But I just can't get it to work. I have OSX Server 10.4.10. I currently have my company site (www.example.com) hosted on it. But I'm trying to get another site hosted on it at port 8080. When I enter my company domain, www.example.com:8080, the page can't be displayed. But when I enter the IP address, such as 192.168.xxx.xxx:8080 from within my network, the correct site shows up. How can I get a website displayed at port 8080 from outside my network? I'm running DD-WRT on my router and have ports 80 and 8080 directed to the IP address of my server.
    Thanks in advance for any help.

    Hi WiFiNetGuy-
    I am a tad confused, which isn't new, but I need to get a grasp on exactly what it is that you are trying to do.
    Do you have both websites (i.e. www.example1.com and www.example2.com) both pointed at the same ip address? How many unique domain names and ip addresses are we talking about?
    From what you describe it sounds like a routing issue but I need more info (:>)
    Luck-
    -DaddyPaycheck

  • Cdemu - can't get it to work (can't connect do dbus, no cdemu module)

    Hi all! As the topic subject says, I can't get cdemu to work.
    I'm trying to use it to mount some .mdf images (wanna play Diablo 2 again, and I really don't wanna use the CDs for this).
    So here goes. First I tried mounting the .mdf image with cdemu, like this...
    cdemu load 0 01.Install.mdf
    I get an error message:
    ERROR: Failed to connect to CDEmu daemon: org.freedesktop.DBus.Error.ServiceUnknown: The name net.sf.cdemu.CDEMUD_Daemon was not provided by any .service files
    ERROR: Failed to connect to daemon (bus: 'session')!
    So I found somewhere that I should compile the cdemu-daemon and cdemu-client...
    yaourt -Sb --noconfirm cdemu-daemon cdemu-client
    now, cdemu-daemon compiles fine, but cdemu-client doesn't seem to compile. what I get as an error is this:
    Byte-compiling python modules...
    __init__.pycdemu.py File "/usr/lib/python3.1/site-packages/cdemu/cdemu.py", line 128
    except dbus.DBusException, e:
    ^
    SyntaxError: invalid syntax
    The full output is in the pastebin.
    So anyway, cdemu client installs (althought the success of this is obviously questionable at best), and when I try mounting an image, I (probably as expected) get this:
    Traceback (most recent call last):
    File "/usr/bin/cdemu", line 23, in <module>
    import cdemu, cdemu.cdemu
    ImportError: No module named cdemu
    A little more digging revealed that cdemu-client is still compiled against python2 rather than python3, so that would probably be the reason why my compile fails.
    I would be very grateful if someone could tell me how to get this thing to work. And if I can help compiling this package properly, please do tell me how.
    Thanks in advance!

    Primoz wrote:First: Try to compile it to python2.
    How exactly do I do that?
    Primoz wrote:Second: Did you add cdemud to your Deamons array; or did sudo /etc/rc.d/cdemud start, before trying to load ISO file with cdemu?
    Third: Do you have vhba-module installed and is it added to modules array?
    Yes and yes.
    defears wrote:
    Try this from terminal. Took a long time for me to get this working too.
    cdemu load 0 /path/to/file.cue -b system
    Thanks! This worked. I can play Diablo 2 now, yaaaay

  • Can't get VLAN to work

    Hello,
    Maybe I'm missing something elementary.. this is my first time trying this out and just can't get it to work.
    I've got an xserve on a netgear smart switch on port 13. The netgear is hooked up to two different networks (204.x.x.x via port 1 and 128.x.x.x via port 2), and I have 2 VLANs setup on the switch (vlan 1 has port 1 and port 13, vlan 2 has port 2 and port 13).
    The xserve's interface that's on port 13 has a 204 IP and works wonderfully on the 204 network. I then tried to setup a VLAN via sys prefs network and that appeared in the network configs list, and gave it a 128 address. However, even with all the right settings, it won't show up at all on the 128 network.
    Is there something basic that I'm missing?

    Oh, thats not exactly what I meant
    Basically:
    The server serves Web and QTSS via 204 to the world via en0.
    Then, there's 5-10 machines or so on 128 (and 1-2 on 204) that sync over 3TB of data to the machine via 128 (this sever is the only one we have on site that has raids hooked up to it, so its the central data storage so to say), so en1 is pretty much completely saturated between 12am and 8am (and during the day when there's a lot of new work going on). Originally we used to do this over the primary web interface and all the web traffic would suffer (and especially qtss... we'd start getting disconnected errors all over the place when we started up massive copies).
    Half of the machines are 204's and the rest are 128's, which is why we want the ability for en1 to be able to talk locally to machines on either 204 or 128, without having to interrupt the main interfact (if that makes any sense). Does that seem like a sensical solution?
    If it also helps visualize a bit:
    I only have access to register 8 machines on the 204, and TONS on the 128, but im not allowed to serve .com traffic on 128. Technically, the 128 does talk to the 204 locally on location, but its done through a nasty switch and we dont see much higher than 10Mbps tops.

  • Can't get slideshow to work!

    Sorry about yet another basic question, but I can't get slideshow to work.
    I have created a My Photos page template, dragged an Album into it. That looks OK, but when I click on play slideshow, nothing happens.
    Enable Slideshow is ticked in Inspector.
    Any help on this?

    What's the URL of your site so we can examine it first hand? How are you uploading the files? Maybe not all files are getting to the server. Wouldn't be the first time that happened.
    OT

Maybe you are looking for

  • Need help with overlapping divs!

    Hey everyone, I'm working on another website and I have come up against a common problem for newbie designers from what I hear, the dreaded overlapping div problem!  I have a 2 column fixed layout with a floating left div.  My left div has my nav bar

  • How do i tell if my macbook is a Intel Core 2 Duo

    ok i when to "about this mac" and the window pops up and under processor it says "1.83 GHz Intel Core Duo" now should it say Intel Core 2 Duo or that? thanks

  • Photoshop CS6 32 Bit HDR crashes on MAC issue

    Photoshop keeps crashing every time I convert a 32 bit image to 8bit. I am using Photoshop CS6 v13.0.4 x64 on MAC OS X 10.6.8.  I goto Image>Mode>8bits/Channel. When the Merge HDR images Dialogue Box comes up I click "Merge". At the following window

  • Ipad 4 connecting to a snow leopard Imac?

    I just got an Ipad 4, I am running snow leopard on both of my computers, when I plug my Ipad into my computer it says I need the newest version of Itunes, but the newest version of Itunes requires that I have at least lion OS. Anyone have any suggest

  • Tiff 8 or 16 bit

    hi, is there a way to realize when a scanned tiff file is saved as 8 or 16 bit? thanks!