HttpURLConnection and the killer Pound (#)

I'm trying to create a part of my application that posts data to an ASP page (on an affiliate's web site).
Originally, I was using the following code to post the data:
URL url = new URL(sPostURL);                    
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
// include fields to post
conn.setRequestProperty("address", sAddress);
conn.setRequestProperty("ste/apt#", sApt);
DataOutputStream dos = new DataOutputStream(conn.getOutputStream() );
dos.writeBytes("");
dos.close();
// Retrieve response
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String sNewLine = in.readLine();
String sResp = "";
while (sNewLine != null) {
  sResp += sNewLine;
  sNewLine = in.readLine();
in.close();Which worked at first, but then when I went back to the code, I must have made a change because it no longer seems to post the data (sAddress and sApt) to the page. So after researching the topic in the forums, I switched to using a tokenized string to store my post data:
URL url = new URL(sPostURL);                    
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
DataOutputStream dos = new DataOutputStream(conn.getOutputStream() );
// include fields to post
String sRequest = "&address=" + sAddress; // BUILD DATA STRING (NEW)
sRequest += "&ste/apt#=" + sApt; // BUILD DATA STRING (NEW)
dos.writeBytes("");
dos.close();
// Retrieve response
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String sNewLine = in.readLine();
String sResp = "";
while (sNewLine != null) {
  sResp += sNewLine;
  sNewLine = in.readLine();
in.close();which posts the data fine, but the pound sign (#) causes the server to return a response code 500. I can't find an easy way to escape the pound sign. I've even tried building the string using the URL encoded value (%23) but it still causes problems. Does anyone have any suggestions? Was I correct in abandoning the first method? if anyone has any guidance I would be very grateful.

I think the first method is more clean, but if you want to use the second one, you should put your request string through a URLEncoder to encode the string first.
--lichu                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • The transaction does not die after the kill and I have to restart Oracle

    Hi,
    I have this very hard issue with my production environment.
    A transaction started from java hangs after the user has closed the browser before the transaction was completed. The transaction remains in wait for "latch free" in v $ transaction.
    When the WebSphre is stopped the transaction is not closed. Neither the kill on Oracle or on Unix conclude the transaction. The restart of the DB is required.
    The rollback segment pointed to by the transaction is always the same. Although the procedure call by java is always the same.
    The database does not have performance problems and only one transaction per day waits for "latch free" and do not closed.
    The problem could be the rollback segment? Why Oracle is unable to resolve the transaction even if the client is dead and the WebSphere off?
    Regards,
    BingoBongo

    The average duration of the transaction is 10/15 seconds.
    When it lasts longer the client is closed and the transaction remains locked. But not always only in a particular case.
    From this moment the transaction is waiting for "latch free" and the value of the field USED_UBLK/USED_UREC does not increase and not decrease.
    The wait event is always the "latch free".
    The kill (Unix, Oralce) has no effect on the transaction.
    The rollback segment is always the same.
    The procedure call is always acts the same.
    The value of "SECONDS_IN_WAIT-WAIT_TIME/100" increases up to a certain point and then start over again.
    This is a snapshot of a transaction that requires restart of the DB:
    STATUS
    SECONDS_IN_WAIT-WAIT_TIME/100
    CR_CHANGE
    XIDUSN
    SECONDS_IN_WAIT
    WAIT_TIME
    STATE
    EVENT
    USED_UBLK
    USED_UREC
    OSUSER
    CLIENT_INFO
    ROW_WAIT_BLOCK#
    ROW_WAIT_OBJ#
    PROGRAM
    MODULE
    ACTIVE
    399,99
    178
    10
    400
    1
    WAITED KNOWN TIME
    latch free
    11
    738
    was5a
    0
    56204
    JDBC Thin Client
    JDBC Thin Client

  • Region Monitoring iOS 7 : didEnterRegion method is not calling when app is killed by user or by OS in iOS 7 only. It is working fine when it is in background. and the same code is working fine with iOS 6 for both app in suspended mode and background mode.

    Region Monitoring iOS 7 : didEnterRegion method is not calling when app is killed by user or by OS in iOS 7 only. It is working fine when it is in background. and the same code is working fine with iOS 6 for both app in suspended mode and background mode. What changes I have to made to work great in iOS 7 also.

    I rewrote code for debugging purpose and tried to catch error using GetLastError();  method,
    but it only printed 0. Below is code snippet; I think Create() throw an exception
    and code goes to catch block. 
    LONG ConnectTS(CString strIP, UINT n_Port)
    try{
              ErrorLog(0,0,"ConnectTS is calling Create [is going to call]","");
              if(!Create())
    // Exception Line
    n_Err = GetLastError();
    return NET_INIT;
    catch(...)
                       DWORD errorCode = GetLastError();
                       CString errorMessage
                       errorMessage.Format("%lu",errorCode);
                       ErrorLog (0, 0, "Image
    System", (LPTSTR)(LPCTSTR)errorMessage);
                       return  IS_ERR_WINDOWS;
    Output: -
    ConnectTS is calling Create [is going to call]
    Image System
    0

  • Purchased episodes of The Killing Season 2 and tried on both ipad and computer - ipad can't download (too big maybe) and computer (Numb) is missing and others are not in sync.  Downloaded most recent itunes.  Help please.

    Purchased the first four episodes of The Killing Season 2 and am so frustrated.  Tried downloading on both my computer and iPad.  Think they might be too big for iPad - says it's downloaded but can't open even though GB says there is enough.  Am missing episode (Numb) on my computer and the ones that I have downloade to computer are not in sync with sound.  Have downloaded newest version if iTunes.  Please help.

    Here's how to do it.
    1. App Store, iTunes Store should have the same AppleID on Computer and iPhones. (Free to share apps, music and books... )
    2. Person A uses the same purchasing account for everything (ie. email, contacts and ...).
    3. Person B have the same purchase account see no. 1 (for App Store and iTunes Store) but create a second AppleID for iCal, e-mail, contacts  and etc.

  • Mistakenly opened all the folders in my library of music and the Finder stopped working. Now every time I restart the mac, all folders are reopened and can not work with the finder and tried killall-KILL Finder and nothing they reappear

    mistakenly opened all the folders in my library of music and the Finder stopped working.
    Now every time I restart the mac, all folders are reopened and can not work with the finder and tried killall-KILL Finder and nothing will reappear

    mistakenly opened all the folders in my library of music and the Finder stopped working.
    Now every time I restart the mac, all folders are reopened and can not work with the finder and tried killall-KILL Finder and nothing will reappear

  • When I set up my Macs, there were 2 sign names - 1 I created and the other was Ghost. The Apple store says that takes up 50% of my hard drive. Can I kill Ghost? Do I just delete it?

    When I set up my Macs, there were 2 sign-up names - 1 I created and the other was "Ghost". The Apple store says that takes up 50% of my hard drive. Can I kill "Ghost"? Do I just delete it?
    Thanks for your help!

    Hello Blisshous,
    It sounds like you have a user account named Ghost, that you want to delete all content from and remove from the computer. This article will help you do that named:
    OS X Lion: Delete a user account
    http://support.apple.com/kb/PH3867
    Choose Apple menu > System Preferences, and then click Users & Groups or click Parental Controls.
    Click the lock icon to unlock it, and then type an administrator name and password.
    Select the user account you want to delete, and then click Delete below the account list.
    Do one of the following:
    Select “Save the home folder in a disk image” to save the folder as a disk image in /Users/Deleted Users/.
    Select “Don’t change the home folder” to leave the home folder in /Users/.
    Select “Delete the home folder” to remove it from the computer. If you want to prevent programs that read raw data from retrieving any files, select “Erase home folder securely.”
    Click OK.
    Keep in mind, if you remove the user and delete the data, without Time Machine you will not be able to restore any data from it in the future.
    Thank you for using Apple Support Communities.
    Cheers,
    Sterling

  • HT201401 I tried to do a suggested update to my 3 and it killed the phone, says it cannot restore it either. What is next?

    How can I restore my 3G I Phone. I tried an I Tunes update from my computer and it wiped my phone. All I get is a picture of a cord attaching to I Tunes and the message on my computer saying unknown error, cannot restore. Really, let's get real here--

    There's more to the error message; specifically, an error number. Without knowing that number no one can help you.

  • HT203167 Hi I have purchase I application at apple store Design Pro 174.99 POUNDS and I the application never went through. but I looked in my credit card bill and the amount is there. please could you help to get my application???

    I purchase an expensive application and is not in my computer. I need some help to see why its not in my computer and the bill of my credit card show that I have payed for it.

    Welcome to the Apple Community.
    Have you tried redownloading it from the Mac App Store.

  • I have an older macbook pro and the hard drive is starting to go (making loud noises). i tried to back up to an external hard drive (my passport essential se) using time machine and the computer keeps shutting down. suggestions to complete backup please?

    I have an older macbook pro and the hard drive is starting to go (making loud noises). i tried to back up to an external hard drive (my passport essential se) using time machine and the computer keeps shutting down. the same thing happens when just trying to save my pictures from iphoto to a flash drive. suggestions to complete backup please?

    Sounds like you'll need to access that drive while it is not booted. You need to replace it anyway, so do that, then one way or another (ext enclusure, et), access it and copy files.
    If you keep trying to boot it, you might kill it for good and not get your files, so just swap it out first.

  • My Macbook Pro 2012 is painfully slow and the battery dies out really fast

    I don't do a lot of downloading or installing on my computer, I basically just use it to browse the internet or use microsoft office. I haven't used much memory and all the specs on my computer seem fine. I recently went to the genius bar at an apple store and they ran a bunch of diagnostic tests but everything seemed to come up normal. I've backed up all my data and even restored my computer to factory settings. However, my computer still has the same problem. I was told I didn't have any viruses or malware/adware problems and the only reasonable solution the genius bar representative told me that it was tiem to upgrade. However, since these laptops cost over $1,500 new I don't think that's a reasonable solution for me. So if anyone could shine a light on what is possibly happening that would be awesome!
    Thank you!

    Pre-Mavericks
    Open Activity Monitor in the Utilities folder.  Select All Processes from the Processes dropdown menu.  Click twice on the CPU% column header to display in descending order.  If you find a process using a large amount of CPU time (>=70,) then select the process and click on the Quit icon in the toolbar.  Click on the Force Quit button to kill the process.  See if that helps.  Be sure to note the name of the runaway process so you can track down the cause of the problem.
    Mavericks and later
    Open Activity Monitor in the Utilities folder.  Select All Processes from the View menu.  Click on the CPU tab in the toolbar. Click twice on the CPU% column header to display in descending order.  If you find a process using a large amount of CPU time (>=70,) then select the process and click on the Quit icon in the toolbar.  Click on the Force Quit button to kill the process.  See if that helps.  Be sure to note the name of the runaway process so you can track down the cause of the problem.
    Try these in order testing your system after each to see if it's back to normal:
    1. a. Resetting your Mac's PRAM and NVRAM
        b. Intel-based Macs: Resetting the System Management Controller (SMC)
    2. Restart the computer in Safe Mode, then restart again, normally. If this doesn't help, then:
    Boot to the Recovery HD: Restart the computer and after the chime press and hold down the COMMAND and R keys until the Utilities menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    3. Repair the Hard Drive and Permissions: Upon startup select Disk Utility from the Utilities menu. Repair the Hard Drive and Permissions as follows.
    When the recovery menu appears select Disk Utility. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the main menu. Select Restart from the Apple menu.
    4. Reinstall Yosemite: Reboot from the Recovery HD. Select Reinstall OS X from the Utilities menu, and click on the Continue button.
    Note: You will need an active Internet connection. I suggest using Ethernet if possible
                because it is three times faster than wireless.
    5. Reinstall Yosemite from Scratch:
    Be sure you backup your files to an external drive or second internal drive because the following procedure will remove everything from the hard drive.
    How to Clean Install OS X Yosemite
    Note: You will need an active Internet connection. I suggest using Ethernet if possible
                because it is three times faster than wireless.

  • I have two excel files I cannot open or delete from my desktop.  One is titled 6ACAD200 and the other file is titled 8D73A700.  How can I get these off of my computer?

    I have two excel files I cannot open or delete from my desktop.  One is titled 6ACAD200 and the other file is titled 8D73A700.  How can I get these off of my computer?

    From the names I'd guess they are temporary files. If excel is running, quit and try again. If they still won't move or delete reboot. If they still won't move or delete...kill a chicken at midnight under an oak tree?

  • Problem with HttpURLConnection and HttpSession.

    Hi,
    Problem with HttpURLConnection and HttpSession.
    I created a HttpSession object in my main class and then called a URL via HttpURLConnection.
    I tried to access the same session object from the servlet called by the URL . but the main session
    is not returned a new seperate session is created.let me know how can we continue the same session in
    the called URL also which is created in main class.
    Thanks
    Prasad

    You are not supported to create a HttpSession by java client. Only J2EE web container can create it.

  • W/zoteroinstalledwedo a window,open() followed by a window.close() in tha window. Zotero remains and the window is still open. How do I close the window with zotero present in FF w/o disabling zotero?

    the js function to window.open() is in pageAA on a tab.
    We click the form or link to open the popup to run a video.
    We have a close button on the popup window.
    When that is clicked the window.close() js is executed on that page leaving Zotero present and the popup still open.
    We've tried using close() window.close() name.window.close() and
    all fail the same way.
    Short of disabling Zotero is there a way to close the popup in FF and any other addons with one shot?

    Thank's but still no fix.
    In safe mode everything works.
    Without Zotero - everything works.
    When the popup is loaded with Zotero, the tab shows a constant "Loading" with the circular in process icon.
    The Zotero icon shows to the left of the tab.
    If I right click on Zotero and close it, the close() js works properly
    Is there a way to do a window.open() with:
    A. no tabs -or-
    B. block all add on's -or-
    C. to kill an add on
    before doing the close()?

  • My iphone 3g is keep searching for network, and the carrier unable to load network list , wat shall i do?  Read more: My iphone 3g is keep searching for network, and the carrier unable to load network list

    My iphone 3g is keep searching for network, and the carrier unable to load network list , wat shall i do?

    Yes, that kind of tallies with my experience ... after 3 days of useless iPhone 3G (BTW, killing 3G on the phone and relying on acquiring AT&T 2G didn't help, it still locked onto T-Mobile with the result that it was draining battery and rebooting frequently!), I ended up visiting the local Apple Store.
    Although the visit was not to resolve the iPhone problem, whilst there I happened to cycle the phone and due to the store having a local AT&T cell, the strength of the local signal meant that I finally re-acquired a AT&T 3G signal ... once locked on again the phone was fine for the next day.
    Nett outcome of this is that I would prefer to lay most of the blame for this debacle on the poor state of 3G support both by AT&T (and US carriers in general), maybe exacerbated in my case by two related events (the local DNC in Denver, which saturated local AT&T cells including 3G and a proliferation of v2.0.0 and v2.0.1 firmwares on iPhones in town, which dragged cell coverage into the weeds).
    It would be nice for future sanity if AT&T and T-Mobile could at least resolve the ability to acquire/release the iPhone gracefully, otherwise I'll be very sceptical of travelling back to the US with only my iPhone, as a self-employeed consultant I can't afford to be out of touch for three days again!

  • My macbook pro wont get passed the apple icon and the little were wheel below it.  Any suggestions on how I can get this thing to atleast get to the home page or sign in page

    This initially started out as me trying to get my battery to work.  my battery was dying after a few minutes so I was trying to kill the battery and recharge it to see if I couldn't get it back to a full charge.  This didn't work but after a day or so I noticed the computer running slow and when I went to start it a couple days later the apple icon page would pop up and the little grey wheel would just whir away below it like it was thinking.  The screen was kinda hard to see.  Since then I have tried several different things to get the computer to fire back up as it should.  I have taken out the battery and left it hoping the internal battery would die and it would reset itself to a default mode.  Didn't work so I then tried taking the battery out and just using the power cord.  This didn't work.  I tried putting the battery out and in while running on the power cord.   this didn't work.  I have tried holding the "alt/option" key and that didn't work.  Although it did give me a different window.  I have tried holding down the "f" keys.  That didn't work.  I have tried installing a disc to try and reinstall the operating system.  That didn't work.  I had to shut it down and restart it holding down the eject key to get the disc back.  I am running out of things I can think of to try so if anyone has any ideas I am open to all of them.
    Thank you,
    Seldovian

    Mac OS X: What is Safe Boot, Safe Mode?
    Mac OS X: Starting up in Safe Mode
    I have tried installing a disc to try and reinstall the operating system.
    Disconnect all peripherals from your computer. Boot from your install disc & run Repair Disk from the utility menu. To use the Install Mac OS X disc, insert the disc, and restart your computer while holding down the C key as it starts up.
    Select your language.
    Once on the desktop, select Utility in the menu bar.
    Select Disk Utility.
    Select the disk or volume in the list of disks and volumes, and then click First Aid.
    Click Repair Disk.
    Restart your computer when done.
    Repair permissions after you reach the desktop-http://docs.info.apple.com/article.html?artnum=25751 and restart your computer.
    If you did manage to reach the desktop after doing any of the above
    my battery was dying after a few minutes so I was trying to kill the battery and recharge it to see if I couldn't get it back to a full charge.
    Apple/About This Mac/More Info/Hardware/Power/Battery Information - copy and paste the information here. Do not include any serial numbers.
    I noticed the computer running slow
    How large is your hard drive and how much hard drive space do you have left?
    Mac OS X (10.4.3)
    Update to 10.4.11 using the combo update or Software Update along with all the other updates that goes along with it.

Maybe you are looking for

  • Help with Easy VPN client split tunneling.

    Can someone please help me with my config for Easy VPN Client split tunneling. At the moment when the VPN is up I have NO access to the Internet from any host. Here's what I am attempting to do. I want only certain host to route all there traffic tho

  • FF 3.6.12 keeps telling me to update to FF 3.6.12

    I have upgraded to Firefox 3.6.12 and have been asked 3 times since doing so to upgrade to Firefox 3.6.12. All systems appear to function as they should. Not sure why I get this question so many times. This version is the only one that has produced t

  • Chart: amount (count) of records per month (and year). How?

    I need to create a chart eventually. Can't get what formula to use. The data is: 1 | 15 Jan 2 | 20 Jan 25 | 14 Mar 26 | 16 Mar 28 | 20 Mar The chart should show amount(count) of records per month(and year). So in this example: Jan: 2 Mar: 3 Hm... tot

  • Rear left sound coming out of front left and ri

    Sound that should be coming out of the rear left speaker is being divided by the front 2 speakers. Anyone know whats going on? i'v tried reinstall windows vista, reinstalling the sound card, made it sure its not the speakers. So i have no idea whats

  • Range chart to display timeline (start and end dates) side by side

    Hi everyone, I've explained my scenario in the image below. I'm using SQL Server 2008 R2 BIDS to accomplish this. Can someone help me or shed some light to get this going?