Search code examples
javascriptpostwinjs

Setting header in Web.HttpClient to contain quotations


I'm trying to make a POST request using Web.HttpClient (JavaScript)

var uri = new Windows.Foundation.Uri(baseURL);
var hc = new Web.HttpClient();
var authHeader = "OAuth authSig=\"dsadsASD\", timestamp=\"123132\"";
var request = new Web.HttpRequestMessage(Web.HttpMethod.post, uri);

request.headers.insert("Authorization", authHeader);

hc.sendRequestAsync(request);

However this is setting the Authorization header to:

authSig=dsadsASD, timestamp=123132

instead of:

authSig="dsadsASD", timestamp="123132"

Any thoughts why? or how I can get around this?


Solution

  • If you set the authorization this way:

    var WebHttp = Windows.Web.Http; // just to fit in StackOverflow :)
    var authHdr = new WebHttp.Headers.HttpCredentialsHeaderValue("OAuth", 
                       authHeader);
    
    request.headers.authorization = authHdr;
    

    The quotes are not stripped from the value.

    Depending on what you're trying to do, you may want to take a look at the WebAuthenticationBroker sample.