Creating a SOAP XMLHttpRequest request in JavaScript - javascript

I'm trying to create a SOAP request in JavaScript, but I get a wrong response.
Here's my request:
callSOAP() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'https://webapi.allegro.pl/service.php', true);
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<SOAP-ENV:Envelope ' +
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:main="https://webapi.allegro.pl/service.php" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
'<SOAP-ENV:Body>' +
'<main:DoGetCountriesRequest>' +
'<main:countryCode>1</main:countryCode>' +
'<main:webapiKey>xxxxxxxx</main:webapiKey>' +
'</main:DoGetCountriesRequest>' +
'</SOAP-ENV:Body>' +
'</SOAP-ENV:Envelope>';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log(xmlhttp.response);
}
};
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
}
I try to call 'DoGetCountriesRequest' method but the response is status code 500 with a message 'Invalid XML'.
Is it the proper way to call a SOAP method in JavaScript? What's wrong with my request?

It looks like you're sending the request to the ?wsdl endpoint - remove that from the URL in your xmlhttp.open() method call to send it to the service itself.
It also seems your SOAP message is malformed - you've closed the SOAP-ENV:Envelope opening tag too early - it also needs to surround your xmlns:xsi and xmlns:xsd namespace definitions:
'<?xml version="1.0" encoding="utf-8"?>' +
'<SOAP-ENV:Envelope ' +
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:main="https://webapi.allegro.pl/service.php"' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' + ...
Follow up edit:
There are some double quotes in your in your countryCode and webapiKey opening tags that need removing and it looks like the message itself doesn't comply with the WSDL - the operation doGetCountries in the WSDL needs a DoGetCountriesRequest object. Try something like:
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<SOAP-ENV:Envelope ' +
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:main="https://webapi.allegro.pl/service.php" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
'<SOAP-ENV:Body>' +
'<main:DoGetCountriesRequest>' +
'<main:countryCode>1</main:countryCode>' +
'<main:webapiKey>xxxxxxxx</main:webapiKey>' +
'</main:DoGetCountriesRequest>' +
'</SOAP-ENV:Body>' +
'</SOAP-ENV:Envelope>';

Related

User agent(browser) doesn't prompt for credentials over https

When I send this request using soap envelope over http UA asks for credentials. When I send it over https UA doesn't ask for credentials but returns 401 error.
I need user to enter credentials this way.
var wsUrl = config.identityServerURL + "/services/RemoteUserStoreManagerService.RemoteUserStoreManagerServiceHttpsSoap11Endpoint/";
namesToEnable.forEach(function (name) {
var soapRequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.ws.um.carbon.wso2.org" xmlns:xsd="http://common.mgt.user.carbon.wso2.org/xsd"> ' +
'<soapenv:Header/> ' +
'<soapenv:Body> ' +
'<ser:setUserClaimValues>' +
'<ser:userName>' + name + '</ser:userName>' +
'<ser:claims> <!--Optional:--> ' +
'<xsd:claimURI>http://wso2.org/claims/identity/accountDisabled</xsd:claimURI> <!--Optional:--> ' +
'<xsd:value>false</xsd:value> </ser:claims> <!--Optional:--> ' +
'<ser:profileName></ser:profileName> </ser:setUserClaimValues> ' +
'</soapenv:Body></soapenv:Envelope>';
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST',
wsUrl, true);
var sr = soapRequest;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status > 200 < 300) {
console.log('DONE');
sap.ui.getCore().byId("DialogOnEnableUser").close();
sap.m.MessageToast.show("User successfully enabled", {duration: 1000});
} else {
console.log('ERR soap req');
}
}
};
// Send the POST request
xmlhttp.withCredentials = true;
xmlhttp.setRequestHeader("SOAPAction", "urn:setUserClaimValues");
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
Sounds to me like a security restriction due to the ongoing fight on web lack of secure connectivity
https://superuser.com/questions/770897/firefox-does-not-prompt-for-password-for-http-authenticated-sites-how-to-make-i
I would try it with other browsers to discard it first.

Web Addin Outlook

I am developing a new web addin for Outlook using EWS and JavaScript. The scope is to get the current email selected and add it to a new email as attachement. Following the instructions found here: https://msdn.microsoft.com/en-us/library/office/dn726694(v=exchg.150).aspx#bk_createattachews -> I have created some functions to do those steps explained in the MSDN documentation. The problem is that I don't get any errors or something that can tell me what I am doing wrong. Here is my Code:
function soapToForwardItemCallback(asyncResult) {
var parser;
var xmlDoc;
if (asyncResult.error != null) {
app.showNotification("EWS Status", asyncResult.error.message);
}
else {
var response = asyncResult.value;
if (window.DOMParser) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(response, "text/xml");
}
else // Older Versions of Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(response);
}
// Get the required response, and if it's NoError then all has succeeded, so tell the user.
// Otherwise, tell them what the problem was. (E.G. Recipient email addresses might have been
// entered incorrectly --- try it and see for yourself what happens!!)
var result = xmlDoc.getElementsByTagName("m:ResponseCode")[0].textContent;
if (result == "NoError") {
app.showNotification("EWS Status", "Success!");
}
else {
app.showNotification("EWS Status", "The following error code was recieved: " + result);
}
}
}
function getCurrentEmail() {
var item = Office.context.mailbox.item;
item_id = item.itemId;
var getMimeContent = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
// ' <soap:Header>' +
// ' <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
// ' </soap:Header>' +
'<soap:Body>' +
'<m:GetItem>' +
// ' xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"' +
// ' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
'<m:ItemShape>' +
'<t:BaseShape>IdOnly</t:BaseShape>' +
'<t:AdditionalProperties>' +
'<t:FieldURI FieldURI="item:MimeContent" />' +
'<t:FieldURI FieldURI="item:Subject" />' +
'</t:AdditionalProperties>' +
'</m:ItemShape>' +
'<m:ItemIds>' +
'<t:ItemId Id="' + item_id + '"/>' +
'</m:ItemIds>' +
'</m:GetItem>' +
'</soap:Body>' +
'</soap:Envelope>'
mailbox.makeEwsRequestAsync(getMimeContent, createMail);
}
function createMail(asyncResult) {
var parser = new DOMParser();
var xmlDoc;
if (asyncResult.error !== null) {
app.showNotification("EWS Status", asyncResult.error.message);
}
else {
var response = asyncResult.value;
if (window.DOMParser) {
xmlDoc = parser.parseFromString(response, "text/xml");
}
else // Older Versions of Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(response);
}
var toAddresses = 'alexandru.banica#rodacsoft.ro';
var addressesSoap = "";
addressesSoap += "<t:Mailbox><t:EmailAddress>" + toAddresses + "</t:EmailAddress></t:Mailbox>";
var soapToCreateNewEmail = '<?xml version="1.0" encoding="utf-8"?>'+
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+
'xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"'+
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"'+
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
' <soap:Header>'+
' <t:RequestServerVersion Version="Exchange2013" />'+
' </soap:Header>'+
' <soap:Body>'+
' <m:CreateItem MessageDisposition="SaveOnly">'+
' <m:Items>'+
' <t:Message>'+
' <t:Subject>Message with Item Attachment (MimeContent)</t:Subject>'+
' <t:Body BodyType="HTML">The attachmen</t:Body>'+
' <t:ToRecipients>'+ addressesSoap
+
' </t:ToRecipients>'+
' </t:Message>'+
' </m:Items>'+
' </m:CreateItem>'+
' </soap:Body>'+
' </soap:Envelope>'
mailbox.makeEwsRequestAsync(soapToCreateNewEmail,soapToGetItemDataCallback);
}
}
function createAttachement(asyncResult) {
var parser = new DOMParser();
var xmlDoc;
if (asyncResult.error !== null) {
app.showNotification("EWS Status", asyncResult.error.message);
}
else {
var response = asyncResult.value;
if (window.DOMParser) {
xmlDoc = parser.parseFromString(response, "text/xml");
}
else // Older Versions of Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(response);
}
var mimeTag = xmlDoc.getElementsByTagName("t:MimeContent")[0].innerText;
var soapToCreateAttachement = '<?xml version="1.0" encoding="utf-8"?>'+
' <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+
' xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"'+
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"'+
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
' <soap:Header>'+
' <t:RequestServerVersion Version="Exchange2013" />'+
' </soap:Header>'+
' <soap:Body>'+
' <m:CreateAttachment>'+
' <m:ParentItemId Id="'+item_id+'" />'+
' <m:Attachments>'+
' <t:ItemAttachment>'+
' <t:Name>Play tennis?</t:Name>'+
' <t:IsInline>false</t:IsInline>'+
' <t:Message>'+
' <t:MimeContent CharacterSet="UTF-8">'+ mimeTag +'</t:MimeContent>'+
' </t:Message>'+
' </t:ItemAttachment>'+
' </m:Attachments>'+
' </m:CreateAttachment>'+
' </soap:Body>'+
' </soap:Envelope>'
mailbox.makeEwsRequestAsync(soapToCreateAttachement,sendEmailAsAttachement);
}
}
function sendEmailAsAttachement(asyncResult) {
var parser = new DOMParser();
var xmlDoc;
if (asyncResult.error !== null) {
app.showNotification("EWS Status", asyncResult.error.message);
}
else {
var response = asyncResult.value;
if (window.DOMParser) {
xmlDoc = parser.parseFromString(response, "text/xml");
}
else // Older Versions of Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(response);
}
var changeKey = xmlDoc.getElementsByTagName("t:ItemId")[0].getAttribute("ChangeKey");
var soapToSendEmailAttachment = ' <?xml version="1.0" encoding="utf-8"?>' +
' <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
' <soap:Header>' +
' <t:RequestServerVersion Version="Exchange2013" />' +
' </soap:Header>' +
' <soap:Body>' +
' <m:SendItem SaveItemToFolder="true">' +
' <m:ItemIds>' +
' <t:ItemId Id="'+ item_id +'"' +
' ChangeKey="'+ changeKey +'" />' +
' </m:ItemIds>' +
' <m:SavedItemFolderId>' +
' <t:DistinguishedFolderId Id="sentitems" />' +
' </m:SavedItemFolderId>' +
' </m:SendItem>' +
' </soap:Body>' +
' </soap:Envelope>'
mailbox.makeEwsRequestAsync(soapToSendEmailAttachment, soapToForwardItemCallback);
}
}
The first function called on button click is getCurrentEmail(). I am not sure if I can do the SOAP calls like that. Any help would be greatly appreciated! Please tell me if you need additional information. Thank you!
I am not sure if I can do the SOAP calls like that.
The following resource describes EWS operations that add-ins support. "m:CreateAttachment" is not one of them; probably you should start from there.
EDIT:
I don't understand how comes you don't get any errors. Are you debugging? Can you hit break point? Well this is all weird.
Now let me tell you what I've done and what issues with your code I noticed ...
I created the simple project and added your code. I called "getCurrentEmail()" function and work just with this function. I didn't verify any other function, because I believe you should do this on your own.
Javascript errors: If you use "strict" JS mode (and you should!) the function has "item_id" variable which is not defined as "var". You should make it local by using "var" keyword. Next when you call "mailbox.makeEwsRequestAsync" the "mailbox" variable is undefined as well. you should call it as "Office.context.mailbox.makeEwsRequestAsync".
EWS request is not properly formed at all. I don't know, may be you played with it, but the example EWS XML from the resource you have provided is different than you are creating by inserting message Id. When I fixed JS errors (look at the point 2 above) and send EWS request it returned starts "Error" and proper description that request is misformed. I have changed the request to match the request provided in example and it returns "success" and information you have requested, as of subject and MIME content.
I will share my code just for the function you have asked and the rest try to do on your own. Here you go ...
function _wrapSoapEnvelope(payload) {
var result = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' +
'xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" ' +
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
'<soap:Header>' +
'<t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
'</soap:Header>' +
'<soap:Body>' + payload + '</soap:Body>' +
'</soap:Envelope>';
return result;
};
function getCurrentEmail() {
var item = Office.context.mailbox.item,
item_id = item.itemId;
var getMimeContent = '<m:GetItem>' +
'<m:ItemShape>' +
'<t:BaseShape>IdOnly</t:BaseShape>' +
'<t:AdditionalProperties>' +
'<t:FieldURI FieldURI="item:MimeContent" />' +
'<t:FieldURI FieldURI="item:Subject" />' +
'</t:AdditionalProperties>' +
'</m:ItemShape>' +
'<m:ItemIds>' +
'<t:ItemId Id="' + item_id + '"/>' +
'</m:ItemIds>' +
'</m:GetItem>'
Office.context.mailbox.makeEwsRequestAsync(_wrapSoapEnvelope(getMimeContent), createMail);
}

Display XML response from javascript file (SOAP Request) on IIS

I am currently using a calender system that has an API I can access with SOAP requests. It exists on an IIS server.
Initially I figured I could create an HTML page that that I would then have use Javascript to return the contents of the SOAP request - and my SOAP requests returns exactly what I want it to, but not in valid XML - it just displays on the screen (currently commented out below).
What I need to know is how do I get a page to return just the valid XML response (and no other tags, so it is recognized as XML)? Would PHP be better suited for this - or ASP?
My current javascript looks like this:
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://myserver/EMSAPI/', true);
//Todays Date now = new Date();
year = "" + now.getFullYear();
month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
todaydate = year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + ".000";
// build SOAP request
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<GetAllBookings xmlns="http://DEA.EMS.API.Web.Service/">' +
'<UserName>EmsAPI</UserName>' +
'<Password>Mypass</Password>' +
'<StartDate>'+todaydate+'</StartDate>' +
'<EndDate>'+todaydate+'</EndDate>' +
'<BuildingID>36</BuildingID>' +
'<ViewComboRoomComponents>false</ViewComboRoomComponents>' +
'</GetAllBookings>' +
'</soap:Body>' +
'</soap:Envelope>';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
ret = xmlhttp.responseText;
//$(document.body).append(ret);
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
// send request
// ...
}
window.onload = function() { soap(); };
My HTML is very straight forward - it is a blank document besides including the javascript.
The problem is I'm using some software that cannot interface with the calender directly - and that software will only accept a valid XML response - so whatever page I write, it has to return just the pure XML so that way when I tell the software the page URL - it is given the XML response appropriately.
Just wondering what other ways there may be to go about this to get it to work. I apologize if the question is confusing - I can elaborate if needed.
I went with Classic ASP in order to do what I wanted it to.
My final code looked like this in classic ASP:
<%
Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")
Dim strRequest, strResult, strFunction, strURL, strNamespace
'URL to SOAP namespace and connection URL
strNamespace = "http://DEA.EMS.API.Web.Service/"
strURL = "http://myserver/EMSAPI/"
'function you want to call
strFunction = "GetBuildings"
'strFunction = "test" 'no parameters required
strRequest ="<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soap:Envelope" &_
" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" &_
" xmlns:api=""http://127.0.0.1/Integrics/Enswitch/API""" &_
" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""" &_
" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &_
"<soap:Body>" &_
"<GetBuildings xmlns=""http://DEA.EMS.API.Web.Service/"">" &_
"<UserName>Myusername</UserName>" &_
"<Password>mypassword</Password>" &_
"</GetBuildings>" &_
"</soap:Body>" &_
"</soap:Envelope>"
objXMLHTTP.open "POST", ""& strURL &"", True
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest)
objXMLHTTP.setRequestHeader "SOAPAction", strNamespace & strFunction
'send the request and capture the result
objXMLHTTP.send(strRequest)
'Set a timer to wait for response
set shell = CreateObject("WScript.Shell")
t1 = timer()
sleep(1)
t2 = timer()
response.write "waited "& t2-t1 &" secs"
function sleep(seconds)
if seconds>=1 then shell.popup "pausing",seconds,"pause",64
end function
strResult = objXMLHTTP.responseText
'display the XML
response.write strResult
%>

I don't know why this script wont't work

For some reason this script won't work. I'm using express, socket.io, jade and node.js.
Here is the script:
var socket = io.connect();
function addMessage(msg)
{
var currentDate = new Date();
var dateTime = currentDate.getDate() + "/" +
(currentDate.getMonth() + 1) + "/" +
currentDate.getFullYear() + "#"
currentDate.getHours() + ":" +
currentDate.getMinutes() + ":" +
currentDate.getSeconds();
$("#historyView").append("<p>" + dateTime + " - " + msg + "</p>");
}
function sentMessage()
{
if ($("#arduinoInput").val() != "")
{
socket.emit("message", $("#arduinoInput").val());
addMessage($('#arduinoInput').val(), new Date().toISOString(), true);
$("#arduinoInput").val("");
}
}
socket.on("message", function(message){
addMessage(message);
});
$document.ready(function(){
$("#submit").click(function(){
sentMessage();
});
});
It doesn't even clear the text box. Here is the jade page:
doctype 5
html
head
title Arduino Controller 2
script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")
script(src="/socket.io/socket.io.js");
script(src="script.js")
link(rel="stylesheet" type="text/css" href="style.css")
body
div.container
header
h1 Arduino Controller 2
center
div#historyView
input(type="text")#arduinoInput
button#submit Send
I've been trying to debug this for awhile. I'm running this on Mac OS X 10.9 if that helps.
Assuming you don't have any other code, this would be incorrect:
$document.ready();
It is likely you meant to attach a ready handler to the document, which should look like this:
$(document).ready();

OAuth, 403 response error on request_token

Receiving http 403 response error when trying to get a
request token.
I've checked my base string's singing process, and that's proper. If
I use the default keys on the Twitter dev site, it generates the same
result as they list on the site, so i'm pretty sure that's okay.
Any insight would be much appreciated!
var reqURL = 'https://api.twitter.com/oauth/request_token';
var reqNonce = getNonce();
var reqTimeStamp = getTimeStamp();
var reqSignatureMethod = 'HMAC-SHA1';
var reqOauthVersion = '1.0';
var reqConsumerKey = 'ySBPkqxaRlheQKFwejMpqg';
var reqConsumerSecret = '______________&' // note the & at the end..
var reqCallback = 'http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11'
var reqQuery = 'oauth_callback=' + reqCallback + '&oauth_consumer_key=' + reqConsumerKey + '&oauth_nonce=' + reqNonce + '&oauth_signature_method=' + reqSignatureMethod + '&oauth_timestamp=' + reqTimeStamp + '&oauth_version=' + reqOauthVersion;
var reqBaseString = 'POST&' + reqURL + '&' + encodeURIComponent(reqQuery);
var reqSignature = b64_hmac_sha1(reqConsumerSecret, reqBaseString);
var reqSignature = reqSignature + '=';
var request = new XMLHttpRequest();
request.onreadystatechange = function(data) {
if (request.readyState == 4) {
// Good response, got the xml file
if (request.status == 200) {
alert ('good response');
}
}
};
// alert (reqURL);
// alert (reqBaseString);
var oauthParams = encodeURIComponent("OAuth oauth_callback=\"" + reqCallback + "\",oauth_consumer_key=\"" + reqConsumerKey + "\",oauth_nonce=\"" + reqNonce + "\",oauth_signature_method=\"" + reqSignatureMethod + "\",oauth_timestamp=\"" + reqTimeStamp + "\",oauth_version=\"1.0\",oauth_signature=\"" + reqSignature + "\"");
request.open("POST", reqURL, true);
request.setRequestHeader("Accept", "text/plain, */*");
request.setRequestHeader("Connection", "Keep-Alive");
request.setRequestHeader("Authorization", oauthParams);
request.send();
What I have found to be immensely helpful is to just get the raw HTTP request that does work with the Netflix OAuth Test that cnauroth suggested and then compare it to what you are sending with this code snippet here. OAuth is tricky and not fun so if you can just diff the two requests you should be able to find some improper encoding or a misplaced &.

Categories

Resources