×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    is XMLHttpRequest setRequestHeader(change 'Content-type' or others) supported?

    my code:

    function http_post(url, data, func) {
    var xhr;
    xhr = new XMLHttpRequest();

    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); //1
    xhr.setRequestHeader("User-Agent", "Mozilla/5.0 (Series40; NokiaX3-02/06.00; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/1.5.0.34.11"); //2
    xhr.setRequestHeader("XXXXXX", "YYYYYYY"); //3
    xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
    if (xhr.status == 200) {
    if (xhr.responseText != null) {
    func(xhr.responseText);
    }
    }
    }
    };
    var body = encodeParam(data);
    xhr.send(body);
    }



    when i use Fiddler to debug this function call. i found Content-type and User-Agent not changed(it's
    Content-Type: image/gif; q=0.5
    User-Agent: S40OviBrowser/1.0.0.9.10 Profile/MIDP-2.1 Configuration/CLDC-1.1 Series40 NokiaX3-02/05.60 WebSDKSimulator/1.5.0.201110122136).

    but the XXXXXX header is added.

    so my question is : can we change Content-type header in an HTTP request and how could we?

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: is XMLHttpRequest setRequestHeader(change 'Content-type' or others) supported?

    Hi and welcome to forum!

    Have you tried checking what "Content-type" header the serve sees, when using actual device? According to my tests it works and content type can be changed.

    When the User-Agent header is set in the XMLHttpRequest it is appended to another user-agent string:
    Code:
    HTTP_USER_AGENT: Mozilla/5.0 (Series40; NokiaX3-02/06.00; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/1.5.0.34.15, Mozilla/5.0 (Series40; NokiaX3-02/06.00; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/1.5.0.99.9 
    //99.9 is the made up user agent, set in the XMLHttpRequest
    What comes to Local preview it seems to have some problems with the content type header. Have to investigate that bit more, but it is very likely a bug.

    Br,
    Ilkka

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    Re: is XMLHttpRequest setRequestHeader(change 'Content-type' or others) supported?

    Hi Ilkka,
    Thanks for your help!
    I have try on clound preview use the same code, it's all right.(I don't know what the server sees but it runs fine).
    Just like you said,maybe it's a bug of Local preview.

Similar Threads

  1. Replies: 3
    Last Post: 2010-05-31, 11:43
  2. XMLHTTPREQUEST can cache the content??? Need help
    By alicenan88 in forum Symbian
    Replies: 3
    Last Post: 2009-11-05, 12:02
  3. Content Type supported MMSC
    By smeagol80 in forum General Messaging
    Replies: 0
    Last Post: 2006-06-29, 16:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×