How do you *unset*  Content-Type when using HttpURLConnection ?

Hi people,
I am using HttpURLConnection to set some http headers. It all works fine except that this utility is setting Content-type to text/html even though I cam not coding it to do so. I can overwrite Content-type by setting it to say, a blank, explicitly in the code, but Content-type still appears as a header (eg if I view the headers in a proxy.)
My question is - how do you completely unset Content-Type? Here's the code snippet :
URL url = new URL("http://mymachine-uk.uk.company.com:24331/test.html");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setIfModifiedSince(longdate); // I've set up longdate previously
// set some headers
con.setRequestProperty("Cache-Control","max-age=0");
con.setRequestProperty("User-Agent","Mozilla/5.0");
con.setRequestProperty("Keep-Alive","300");
// I've tried hacking it like this :
// con.setRequestProperty("Content-type",null);
// but that just shows an empty Content-type, rather than get rid of it.
// In a proxy window on port 24331, the three headers set explicitly above
// all show up correctly. But Content-type:text/html is also shown, even though not coded.
// If I fire off the same page request from a browser, Content-type ISN'T set.
// so there must be a way of doing it :-) Help!
thanks.
Edited by: colin_the_aardvark on Feb 24, 2010 1:45 AM

Hi there,
thanks very much for trying this, the background to this is as follows :
I am testing a software server caching product which is giving me weird behaviour; the actions the cache performs are supposed to be based on the various http headers. I am using a debug proxy ("Charles") (limited freeware-for-a-short-period) to see exactly what http headers are being set by the calling browser, or in this case, the java program. I am setting the headers directly in the code above to match what my browser is setting, as revealed by Charles. Trouble is, I'm getting different reponses back: The browser gets a http 304 from the cache and my java program gets a 200, so I have obviously failed to emulate the browser.. and the only difference I can see is that the Conetnt-Type is not set when I call the page from internet explorer, but with my program above, Content-Type is set, to a default of text/html. I want to get rid of it so I have copied the browser http header settings 100%.
- I tried compiling this code and running it from the prompt (outside of development environment) and Content-Type is still showing up. So from what you are saying... if your attempt does not set this.. then it looks like Content-type must be getting set via some other means?
thankyou :-)

Similar Messages

  • How to set "Files of type" when using a "File Browse" item.

    Apex 4.0.2
    Internet Explorer 7 +
    I have a "File Browse" item on a page and need to limit the types of files display to just "text (.txt)" files. How can this be done? Currently, the "Files of type" list shows "All File (*.*)", "Pictures (*.gif,*.png)", and HTML (*.htm,*.html)". In the best case, I would like to not have the "Files of type" list and have the user just limited to text files. However, adding Text files (*.txt)" to the "Files of type" list is ok.
    thanks,
    William

    Thought i'd do a bit of research after seeing Scotts wonderful ideas.
    So it turns out, IE made the file item read only from version 8, for security reasons. Read more: http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
    File Upload Control
    Historically, the HTML File Upload Control (<input type=file>) has been the source of a significant number of information disclosure vulnerabilities. To resolve these issues, two changes were made to the behavior of the control.
    To block attacks that rely on “stealing” keystrokes to surreptitiously trick the user into typing a local file path into the control, the File Path edit box is now read-only. The user must explicitly select a file for upload using the File Browse dialog.
    Additionally, the “Include local directory path when uploading files” URLAction has been set to "Disable" for the Internet Zone. This change prevents leakage of potentially sensitive local file-system information to the Internet. For instance, rather than submitting the full path C:\users\ericlaw\documents\secret\image.png, Internet Explorer 8 will now submit only the filename image.png.To resetting the actual items, suggestions I found were to replace the actual item. So instead of using $s, I just replace the element, with the existing element, causing it to re-initialise.
    var htmldb_delete_message='"DELETE_CONFIRM_MSG"';
    function fileCheck(el){
        if(el.value){
            var validFile = false;
            var validExtensions = ["csv"];
            var filename = el.value;
            var fileExtIndex = filename.lastIndexOf(".");
            var fileExt = filename.substring(fileExtIndex+1, filename.length);
            for(i = 0; i < validExtensions.length; i++){
                if(validExtensions[i] == fileExt){
                    validFile = true;
                    break;
            if ( !validFile || fileExtIndex == -1) {
                alert("Invalid Extension. Permitted files must end with: " + validExtensions.toString());
                var htmlContents = el.outerHTML || new XMLSerializer().serializeToString(el);
                $('#P16_BINARY').replaceWith(htmlContents);
    }(obviously, replacing what you need to, to suit your page - i prefer scotts idea of passing in supported file types in the function, so would just pass in an array instead; but this is just for demonstration)
    with an onchange="checkFile(this)" on the element attributes.
    On a slightly un-related note, I found out IE doesn't support the wonderful indexOf function on arrays, that checks for the existence of the value in an array. Sucks.
    Edited by: trent
    Ah well, jQuery is there, maybe i should use that for searching arrays in the future.
    http://api.jquery.com/jQuery.inArray/
    Edited by: trent
    Forgot a demo link, for csv files: http://apex.oracle.com/pls/apex/f?p=45448:16
    Edited by: trent
    Modify function. Didn't work in Firefox

  • How can you Keep column links when using export CVS

    I am exporting a report using Report Template of export: CVS. This report is a copy of a report that have column links that work. However, when I export the report using export: CVS the excel file no longer has the links in the columns.
    How can I get the link to be transferred to excel?
    Thanks

    446336,
    When you export anything as CSV type it is a plain ordinary text file - MS Excel opens it because it has knowledge of this type of file (ie text delimited by comma/tab).
    You seem to need a bit more than that - best if you search the forum for ¨excel¨ or maybe ¨report exports¨. I believe there are some threads here that may help - I think it needs java or some fancy PL/SQL to do it.
    Greg

  • How do you turn off sounds when using phone?

    I know this question is not appropriate for this forum but I cannot find where it should go. I want to turn off the sounds when I am using my phone, e.g., when I am texting, each time I press a key it make a sound. If I turn down the volume then I cannot hear it ring so this is not the answer.
    I have the Nokia 7020 phone. I cannot find any help in the userguide, only how to change ring tones. Anyone have any idea? Thank you.
    Solved!
    Go to Solution.

    On my Lumia 900, it's under Settings -> ringtones+sounds, scroll to the bottom where there is a list of check boxes, and uncheck "Key press".  Not sure it's the same for your phone, though.

  • How do you recognize JLabel pictures when using mouseListener

    Im doing a project where im making parcheesi. for this project im using mouseListener and JLabel images on top of JPanel squares. I need to be able to be able to recognize each color in order to either move the image or to create a new one. Any pointers on how to do this?

    It sounds like you're starting your game with the GUI. It's generally a better idea to get the actual workings of the game out of the way first and worry about the GUI last. A command line parcheesi game might not be pretty, but it's probably best to program your GUI independently of game function.
    For example, store the parcheesi board in a 2D array (or something of the sort) of chars. Then you can have a function the draws the board based on that array. Clicking and dragging would also use that array to paint the appropriate pieces. But like I said, that should be your last step.
    That's just me though. People tend to rush into the GUI part of a program, even after advised to do otherwise.

  • Pre - How do you silence external ringer when using headphones?

    When I get a call while using the headphones, I'd like to hear the ringer in my headphones only... Currently when I get a call it rings in the headphones AND via the external speaker. So let's say Im sitting in church listening to music on my phone :-)... and I happen to get a call, instead of me just hearing the call in my headphones, the entire church gets to hear my phone ring as well...
    I have tried silencing the phone but that silences the ringer in the headphones as well.
    It seems like I could do this on the first phone I had (I took my first pre back for various other reasons)... but for whatever reason I cannot seem to make it work on the new phone. Maybe Im just not setting the preferences correctly... Any suggestions?
    Post relates to: Pre p100eww (Sprint)

    You can use GP. Search the administrative templates for Prevent Running First Run Wizard
    If my answer helped you, check out my blog:
    DeployHappiness. Subscribe by
    RSS or
    email. 

  • How can you see the progress when using a ForEach loop?

    Hi,
    I have an array with about 100 containers in it. My main thread uses a ForEach loop with an inner case structure with six possibilities. My previous program had all the steps in a very long list, executing them one by one. I find this new approach is much nicer to look at, and easier to change, but there isn't really any way of telling how far along the test is (unless you know it by heart). In the long list approach, you could see all the Done/Passed outcomes and how many remained, now there is no way of telling.
    Any tips on making some kind of progress indication? 
    Solved!
    Go to Solution.

    As ObjectReference parameter, you should use 'Nothing'. The last parameter (synchronuous?) you can choose true or false. Please refer to the documentation of PostUIMessageEx for further information.
    The numeric parameter should range between 0-100. Since it is "Progress Percent", this makes sense, does it?
    The status bar has several panes, one e.g. displaying the logged in user or the used process model. The pane on the right most side will display the Progress Percent if used in your sequence.
    The default reporting, as already stated, includes this feature. So if you have a sequence with e.g. 500 steps, the reporting "will have a visible progress" in that pane (with less than 100 steps, it is most often too fast to see). Remember that NI Sequence Editor and the Full Featured User Interfaces do have this feature, the Simple UI does not have it.
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • How do you disconnect Publish site when using a test copy of the website?

    To sort out a solution for accessibility, I made a copy of the live Muse file called "Testing" and did my experiements on this. However, how can i disconnect this copy from the live website as I might click Publish accidentally not realsing I am in the testing site and it will synchronise with the live site (which it also tries to do when I open the "testing" Muse file as in the meanwhile changes have been made to the live site). In other words, I want Muse to treat this copy as a new site, not a variation of the live one but I can't find anyway of doing this inside Muse?

    Publish the test site to a new trial BC site (meant for testing) so the next time you hit the Publish button accidentally, it connects to this newly created test website.
    Thanks,
    Vinayak

  • How do you enable isight camera when using MSN?

    Or isn't it possible? My kids also tell me MSN + is a lot better, but that doesn't appear to be available for mac. I read somewhere you can link ichat to MSN using something called Jabber. Any ideas anyone?
    Thanks

    I use SightSpeed for use with my uncool Windows friends:
    http://www.sightspeed.com/personal
    It is free and easy to work with, both parties need to have it on their computers. In my experience everything is a pale second to iChat, I have tried them all. Loving iChat!
    SZ

  • How can you keep your iPhone 4 (using it as my car's iPod) staying on the Audible app?  When I leave the car and return to continue hearing a book, it has switched to iTunes.

    How can you keep your iPhone 4 (using it as my car's iPod) staying on the Audible app?  When I leave the car and return to continue hearing a book, it has switched to iTunes.

    The first time an iPhone is connected to iTunes that is used to sync with another iPhone or iOS device, you are prompted to transfer the backup for the other iPhone or iOS device or to set up the iPhone as a new iPhone.
    The former does as provided - it transfers the backup for the other iPhone or iOS device to the iPhone replacing all data on the iPhone that is included with the backup being transferred. The latter does nothing allowing you to make your various selections for the iPhone sync preferences with iTunes.
    This is designed to be done right away with a new iPhone.
    If you don't have a backup for the iPhone with iTunes on your computer and don't have an iCloud backup that hasn't been updated since choosing to transfer the backup for your iPod Touch to the iPhone, the data that was on the iPhone is gone.

  • HT3771 how do you delete printer in last use when you try to add new printer again

    how do you delete printer in last use when you try to add new printer again?

    System Preferences > Print & Scan (Print & Fax on older versions of OS X)
    Select the printer and click the "–" (minus) button.

  • [svn] 674: LCDS-110: If you don' t specify file type when using DocumentReference, a java.lang. NullPointerException occurs.

    Revision: 674
    Author: [email protected]
    Date: 2008-02-27 09:41:30 -0800 (Wed, 27 Feb 2008)
    Log Message:
    LCDS-110: If you don't specify file type when using DocumentReference, a java.lang.NullPointerException occurs.
    qa: yes
    bug: LCDS-110
    doc: no
    checkintests: passed
    Details:
    modules/common/src/java/flex/messaging/errors.properties
    * new error message
    Ticket Links:
    http://bugs.adobe.com/jira/browse/LCDS-110
    http://bugs.adobe.com/jira/browse/LCDS-110
    Modified Paths:
    blazeds/branches/3.0.x/modules/common/src/java/flex/messaging/errors.properties

    Yes I know that ;) and I fixed it myself too by initializing it like this: private GameObject[] apple = new GameObject[max_apples];But now I get this error instead:
    Exception in thread "Thread-4" java.lang.ArrayIndexOutOfBoundsException: 3
         at Main.run(Main.java:35)
         at java.lang.Thread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 3
         at Main.paint(Main.java:134)
         at sun.awt.RepaintArea.paintComponent(Unknown Source)
         at sun.awt.RepaintArea.paint(Unknown Source)
         at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)So now I need help on this... =D CHEERS! :P

  • How do i edit content type name or remove in applications panel

    how do i edit content type name or remove the name in applications panel.In the App panel the name is Winrar zip Archive. when i try to download rar file is all way ask me what to do.when i download zip file is save the files.I would like to add rar to the Applications panel

    The MIME Edit extension for Firefox 3.0 - 3.7 versions is available here:
    http://space.geocities.yahoo.co.jp/gl/alice0775/view/20080912/1221150790
    The developer who updated that extension is from Japan, and that website won't be completely readable if you don't have the correct language package installed.
    You can download it directly from this link and save it to local disk.
    http://space.geocities.jp/alice0775/STORE/mime_edit-0.601004242000.xpi
    Then use File > Open File... to install that extension.

  • Choose which content type to use in sharepoint 2013 list using InfoPath 2013

    So, in my head it seems pretty simple and a feature that might be standard to InfoPath so much in fact I can't find anything on it... My goal is to a have one list where you can do a drop down or buttons to choose which content type to use.
    I will be royally disappointed if this is not possible. =(
    So, c'mon you giants of MS Support. Give me a happy answer.

    Hi Lincoln,
    According to your description, my understanding is that you want to use multiple content types in a list.
    For achieving it, you can do as the followings:
    Open the list.
    Go to List Settings->Advanced Settings.
    Under ‘Allow management of content type’, select ‘Yes’, click OK.
    In the Content Types section, click ‘Add from existing site content types’
    Then add the content types that you want to add, click OK
    Go back to the list, click ITEMS->New Item, then all content types are displayed in the drop-down list
    When you click an item, you can select the new item is created based on one of these content types
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • How to create external content type in sharepoint for salesforce account

    Can anybody help me on How to create external content type in sharepoint for salesforce account.
    I wanto upload documents to a document library which should sync with accounts in saleforce.
    thanks in advance

    Hi,
    The following materials would be helpful:
    Tutorial: Access Salesforce Leads in SharePoint through an External List
    http://geekswithblogs.net/dataintegration/archive/2014/02/03/tutorial-access-salesforce-leads-in-sharepoint-through-an-external-list.aspx
    Salesforce SharePoint Integration – Best Practices
    http://rainforce.walkme.com/salesforce-sharepoint-integration-best-practices/#.VFxra3mKAeE
    If you want to upload documents to SharePoint document library from the Saleforce, we can also customize your own web service using SharePont .Net Client Object Model or REST to achieve it.
    Best Regards 
    Dennis Guo
    TechNet Community Support

Maybe you are looking for